从照片中获取Exif信息

时间:2014-12-12 08:53:03

标签: c# windows-phone-8 stream photo exif

我想使用ExifLib从Photo中读取exif信息,第一种方法已经完成,因为我使用了PhotoChooserTaskphotoChooserTask.Completed += (s, e) => {PhotoConverter.GetMetaData(e);} 以及获取exif信息的方法

public static void GetMetaDate(PhotoResult e)
{     
    ExifLib.JpegInfo info = ExifLib.ExifReader.ReadJpeg(e.ChosenPhoto);
    var img = new BitmapImage();
    img.SetSource(e.ChosenPhoto);
    App.MainViewModel.MetaDate = ReadExif(info);
}

private static string ReadExif(JpegInfo info)
{
    JsonObject metaDate = new JsonObject();
    metaDate.Add("FNumber", info.FNumber);
    return metaDate.ToString();
}

这很棒,但问题是当我想从手机画廊分享图片时。我获取图片的方式看起来像这样

if (queryStrings.ContainsKey("FileId"))
{
     MediaLibrary library = new MediaLibrary();
     Picture photoFromLibrary = library.GetPictureFromToken(queryStrings["FileId"]);
     BitmapImage bitmapFromPhoto = new BitmapImage();
     bitmapFromPhoto.SetSource(photoFromLibrary.GetImage());
}

那么,我应该如何更改我的GetMetaDate来阅读photoFromLibrary.GetImage

1 个答案:

答案 0 :(得分:1)

好的,我找到了简单的方法

public static void GetMetaData(Stream photo)//change to stream
{
    ExifLib.JpegInfo info = ExifLib.ExifReader.ReadJpeg(photo);
    var img = new BitmapImage();
    img.SetSource(photo);
    App.MainViewModel.MetaDate = ReadExif(info);
}

并使用MediaLibrary添加流

if (queryStrings.ContainsKey("FileId"))
{
     // Retrieve the photo from the media library using the FileID passed to the app.
     MediaLibrary library = new MediaLibrary();
     Picture photoFromLibrary = library.GetPictureFromToken(queryStrings["FileId"]);

     //Get metadate
     Stream stream = photoFromLibrary.GetImage();
     PhotoConverter.GetMetaData(stream);
}