Is ExifLib usable in a WPF / XAML app?

醉酒当歌 提交于 2019-12-02 06:42:50

The string constructor is not available in Windows Phone/Windows Store apps because they aren't allowed direct filesystem access. You will instead need to pass in a stream containing your image. Here's an example using a FileOpenPicker. Note the use of AsStream(...) to convert the IRandomAccessStream into a Stream for use with an ExifReader.

using System;
using System.IO;
using Windows.Storage;
using Windows.Storage.Pickers;

// ...

var picker = new FileOpenPicker();
picker.FileTypeFilter.Add(".jpg");
var file = await picker.PickSingleFileAsync();

using (var randomAccessStream = await file.OpenAsync(FileAccessMode.Read))
{
    using (var stream = randomAccessStream.AsStream())
    {
        using (var reader = new ExifReader(stream))
        {
            string model;
            if (reader.GetTagValue(ExifTags.Model, out model))
            {
                var dialog = new MessageDialog(model, "Camera Model");
                dialog.ShowAsync();
            }
        }
    }
}

this has nothing to do with WPF
try something like this

using (ExifReader reader = new ExifReader(File.Open(@"C:\temp\testImage.jpg",FileMode.Open)))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!