Spaso Lazarevic
Spaso Lazarevic

Reputation: 906

Read Exif data from Image on WP

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

Upvotes: 1

Views: 2712

Answers (2)

JustinAngel
JustinAngel

Reputation: 16092

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();  

Upvotes: 1

Igor Kulman
Igor Kulman

Reputation: 16361

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.

Upvotes: 1

Related Questions