【问题标题】:UWP: How to take photo with all metadata using MediaCapture?UWP:如何使用 MediaCapture 为所有元数据拍照?
【发布时间】:2019-05-01 16:15:18
【问题描述】:

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

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

【问题讨论】:

    标签: uwp camera metadata exif mediacapture


    【解决方案1】:

    要获取图像特定的属性,您需要调用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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-26
      • 1970-01-01
      相关资源
      最近更新 更多