UWP:如何使用MediaCapture拍摄所有元数据的照片?

时间:2018-11-29 14:55:01

标签: uwp camera metadata exif mediacapture

现在我使用MediaCapture.CapturePhotoToStorageFileAsync拍照,但是没有exif元数据。我尝试使用SoftwareBitnmap类,但仅获得BitmapPropertySet,仅包含制造商和模型数据。

我需要设备可以支持的所有元数据,例如使用Windows 10在Camera应用程序中构建照片。

1 个答案:

答案 0 :(得分:0)

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

如果要访问更大的文件元数据集,则需要使用ImageProperties.RetrievePropertiesAsync方法。有关更多信息,请参见Image Metadata

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

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 Properties

     

某些属性仅适用于某些文件容器和图像编解码器。有关每种图像类型支持的图像元数据的列表,请参见Photo Metadata Policies

     

由于不支持的属性在检索时可能返回null值,因此在使用返回的元数据值之前,请始终检查null。