从WP上的Image中读取Exif数据

时间:2012-12-05 12:06:26

标签: windows-phone windows-phone-8

如何从Image中读取Exif数据。 有ExifLib但Lumia设备和数据采集字段有问题。 有没有其他方法可以在Windows Phone上读取Exif数据(7./8)。

祝你好运

2 个答案:

答案 0 :(得分:1)

我使用本文http://igrali.com/2011/11/01/reading-and-displaying-exif-photo-data-on-windows-phone/中的ExifLib,在Lumia 800和710上没有任何问题。试试吧。如果您想获取照片的位置,请确保您已在设置中启用的照片中添加gps信息。

答案 1 :(得分:1)

你应该使用ExifLib。不幸的是,它需要更多的工作,因为它不是100%适应WP。

1)下载ExifLib ZIP,解压缩,解锁DLL(右键单击 - >属性 - >取消阻止)并从项目中添加对它的引用。我同时@ http://JustinAngel.net/Storage/ExifLib.zip

在我的服务器上托管了ZIP

2)接下来,您必须创建一个可从Windows Phone使用的输入功能。这是我使用的那个:

public class ExifReaderEx : ExifReader
{
    protected ExifReaderEx(Stream stream)
        : base(stream)
    {
    }

    public static JpegInfo ReadJpeg(Picture picture)
    {
        Stream FileStream = null;
        try
        {
            FileStream = picture.GetImage();
        }
        catch
        {
            return null;
        }

        DateTime now = DateTime.Now;
        ExifReaderEx reader = new ExifReaderEx(FileStream);
        reader.info.FileSize = (int)FileStream.Length;
        reader.info.FileName = string.Format("{0}.jpg", "fileName");
        reader.info.LoadTime = (TimeSpan)(DateTime.Now - now);
        return reader.info;
    }
}

3)通过调用ExifReaderEx.ReadJpeg(myPicture)来调用代码。例如,以下代码段将返回包含所有元数据的Exif项列表:

            var items = 
                new MediaLibrary().Pictures
                    .Select(picture => ExifReaderEx.ReadJpeg(picture))
                    .Where(exif => exif != null)
                    .ToList();