【问题标题】:Changing the Creation date in a picture while creating it with StorageFile使用 StorageFile 创建图片时更改图片中的创建日期
【发布时间】:2015-08-25 14:40:40
【问题描述】:

我正在使用 Storagefile 在 Windows Phone 8.1 的照片库中保存图片相册中创建图片,到目前为止这项工作还可以。我使用来自我保存到这张新图片的图片的流,在下面您将看到代码 sn-p。我的问题是新创建的图片有流(源文件)的创建日期,如何将新文件创建日期更改为DateTime.Now?!

这是我保存图片的方法:

    var pictureURL = "ms-appx:///Assets/folder/Picture.jpg";

    StorageFile storageFile = await KnownFolders.SavedPictures.CreateFileAsync("Picture.jpg", CreationCollisionOption.GenerateUniqueName);

    StorageFile pictureFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri(pictureURL));

    using (var imageFile = await pictureFile.OpenStreamForReadAsync())
    {
            using (var imageDestination = await storageFile.OpenStreamForWriteAsync())
            {
                 await imageFile.CopyToAsync(imageDestination);
            }
    }

如你所见,上面的 sn-p 创建了一个名为“storageFile”的新图片,然后从 Application Uri 获取文件,即“pictureFile”。然后通过 using 打开源图片以读取为流,在此使用另一个 using 语句打开画廊中新创建的图片文件进行写入,其中打开的文件数据被复制到目标文件数据并保存。

这可行,文件在图库中,但创建时间来自源图片。我如何在运行时向它添加新的创建时间?!

【问题讨论】:

  • jpg有EXIF信息吗?
  • @Rowland 是的,它有 EXIF,我需要一种方法来从流中创建新图片来删除这些数据,并且只在创建新文件时使用这些数据。我在 Windows.Storage.FileProperties 中找到了 ImageProperties,但我怎样才能将它添加到我的代码中而不会出现拒绝访问异常。

标签: c# windows windows-phone-8.1 windows-phone storagefile


【解决方案1】:

这是解决方案:

我在 Windows.Storage.FileProperties 中找到了 ImeProperties,使用下面的编辑代码,您可以保存图片,并在它更改 EXIF 数据(如拍摄日期和相机制造商等详细信息)后立即保存。

    var pictureURL = "ms-appx:///Assets/folder/Picture.jpg";

    StorageFile storageFile = await KnownFolders.SavedPictures.CreateFileAsync("Picture.jpg", CreationCollisionOption.GenerateUniqueName);

    StorageFile pictureFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri(pictureURL));

    using (var imageFile = await pictureFile.OpenStreamForReadAsync())
    {
        using (var imageDestination = await storageFile.OpenStreamForWriteAsync())
        {
             await imageFile.CopyToAsync(imageDestination);
        }
    }

    ImageProperties imageProperties = await storageFile.Properties.GetImagePropertiesAsync();

    imageProperties.DateTaken = DateTime.Now;
    imageProperties.CameraManufacturer = "";
    imageProperties.CameraModel = "";

    await imageProperties.SavePropertiesAsync();

这将覆盖现有数据,这就是我要搜索的内容。

【讨论】:

    猜你喜欢
    • 2021-06-28
    • 2020-12-21
    • 2010-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多