Search code examples
xamarinexifxamarin.macexiflib

Xamarin mac 2.10 compatible exif library


I used https://www.nuget.org/packages/ExifLib.PCL/ library, before update.

I'm not able to use this library now :

Could not install package 'ExifLib.PCL 1.0.1'. You are trying to install this package into a project that targets 'Xamarin.Mac,Version=v2.0', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

Any alternative ?

I use Exif library to get image taken date:

using (var stream = File.Open (filePath, FileMode.Open)) {
                var ein=new CGImagePropertiesExif ();
                var jpegInfo = ExifReader.ReadJpeg (stream);
                if (jpegInfo.DateTimeOriginal != null) {
                    takenDate = DateTime.ParseExact (jpegInfo.DateTimeOriginal, "yyyy:MM:dd HH:mm:ss", null);
                }
            }

this code terminates application , also can't seen any exceptions :(

if I just mock datetime , like this:

static DateTime GetMyImageTakenDate (NSUrl url)
        {
            DateTime takenDate = DateTime.Today;

            using (var stream = File.Open (url.Path, FileMode.Open)) {

                takenDate = DateTime.ParseExact (DateTime.Now.ToString ("yyyy:MM:dd HH:mm:ss"), "yyyy:MM:dd HH:mm:ss", null);
            }
            return takenDate;
        }

application works fine :/


Solution

  • Your code works fine for me:

    var filePath = "/Users/sushi/Desktop/img_1771.jpg";
    using (var stream = File.Open(filePath, FileMode.Open))
    {
        var jpegInfo = ExifReader.ReadJpeg(stream);
        if (jpegInfo.DateTimeOriginal != null)
        {
            var takenDate = DateTime.ParseExact(jpegInfo.DateTimeOriginal, "yyyy:MM:dd HH:mm:ss", null);
            Console.WriteLine(takenDate);
        }
    }
    

    Output:

    12/14/2003 12:01:44 PM
    

    Using:

    Xamarin.Mac Version: 2.10.0.105
    ExifLib.PCL Version: 1.0.2-pre01