Read Exif data from Image on WP

冷暖自知 提交于 2019-12-23 02:44:28

问题


How to read Exif data from Image. There is ExifLib but have problem with Lumia device and Data taken field. Are there any other way to read Exif data on Windows Phone (7./8).

Best regards


回答1:


I use the ExifLib from this article http://igrali.com/2011/11/01/reading-and-displaying-exif-photo-data-on-windows-phone/ without any problems on Lumia 800 and 710. Try it. If you want to get the location of the photo, make sure you have adding gps info to photos enabled in settings.




回答2:


You should use ExifLib for that. Unfourtunately it takes a bit more work since it's not 100% adapted to WP.

1) Download the ExifLib ZIP, unzip it, unblock the DLL (right click --> Properties --> Unblock) and add a reference to it from your project. I've hosted the ZIP on my server in the meanwhile @ http://JustinAngel.net/Storage/ExifLib.zip

2) Next you'll have to create an entry function which is usable from windows phone. Here's the one I use:

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) Invoke the code by calling ExifReaderEx.ReadJpeg(myPicture). For example the following code snippet will return a list of Exif items with all metadata:

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


来源:https://stackoverflow.com/questions/13722898/read-exif-data-from-image-on-wp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!