0

现在我使用 MediaCapture.CapturePhotoToStorageFileAsync 拍照,但其中没有 exif 元数据。我尝试使用 SoftwareBitnmap 类,但只获得了带有制造商和模型数据的 BitmapPropertySet。

我需要设备可以支持的所有元数据,例如使用 Windows 10 内置相机应用程序制作照片。

4

1 回答 1

0

要获取特定于图像的属性,您需要调用GetImagePropertiesAsync。返回的ImageProperties对象公开了包含基本图像元数据字段的成员。

如果要访问更大的文件元数据集,则需要使用ImageProperties.RetrievePropertiesAsync方法。请参阅图像元数据 了解更多信息。

以下是一个简单的代码示例:

FileOpenPicker fileOpenPicker = new FileOpenPicker();
fileOpenPicker.FileTypeFilter.Add(".jpg");
fileOpenPicker.FileTypeFilter.Add(".png");
fileOpenPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;

StorageFile imageFile = await fileOpenPicker.PickSingleFileAsync();
if (imageFile != null)
{
    ImageProperties props = await imageFile.Properties.GetImagePropertiesAsync();
    var requests = new System.Collections.Generic.List<string>();
    requests.Add("System.Photo.EXIFVersion");
    IDictionary<string, object> retrievedProps = await props.RetrievePropertiesAsync(requests);
    if (retrievedProps.ContainsKey("System.Photo.EXIFVersion"))
    {
        var exifVersion = (string)retrievedProps["System.Photo.EXIFVersion"];
    }
}

请注意:

有关 Windows 属性的完整列表,包括每个属性的标识符和类型,请参阅Windows 属性

某些属性仅支持某些文件容器和图像编解码器。有关每种图像类型支持的图像元数据的列表,请参阅照片元数据策略

因为不受支持的属性在检索时可能会返回空值,所以在使用返回的元数据值之前始终检查空值。

于 2018-11-30T07:42:22.860 回答