0

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 :/

Nininea
  • 2,671
  • 6
  • 31
  • 57

1 Answers1

0

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
SushiHangover
  • 73,120
  • 10
  • 106
  • 165
  • this code is use inside modal. here is main process, I should get taken date while uploading info and also should copy image inside my directory, without getting taken date application works fine. when I try to get date , application stops working , but it pass all lines, doesn't throw any exception – Nininea Oct 18 '16 at 13:11
  • @Nininea You need to step line by line through the code and determine what line is causing the crash (or is the application just exiting normally?) – SushiHangover Oct 18 '16 at 13:16
  • I know debugging, but it is not a simple case. without getting date from exit only modal is closed (as expected), but if I added this code , what I wrote all lines will be executes inside file upload method and than application is terminated (it shouldn't be so ) – Nininea Oct 18 '16 at 13:37
  • I was working for me too, after update xamarin version it stopped working :( – Nininea Oct 18 '16 at 13:38
  • Then just mock `takenDate` with a date in the line after `takenDate = DateTime.ParseE....` as a debugging test... and trace/debug it from there. – SushiHangover Oct 18 '16 at 13:43
  • I have changed code : using (var stream = File.Open (url.Path, FileMode.Open)) { var jpegInfo = ExifReader.ReadJpeg (stream); takenDate = DateTime.ParseExact (DateTime.Now.ToString ("yyyy:MM:dd HH:mm:ss"), "yyyy:MM:dd HH:mm:ss", null); } it seems it works – Nininea Oct 18 '16 at 13:50
  • I accept your answer, cause ExifLib.PCL Version: 1.0.2-pre01 is compatible . for the main problem , I had I wrote work around : http://stackoverflow.com/questions/40113284/get-image-taken-date-xamarin-mac – Nininea Oct 19 '16 at 09:51