Получить дату съемки изображения xamarin mac

Мне нужно получить дату съемки изображения без дополнительных библиотек exif, то, что я нашел в документации, у меня не работает:

CGImageSource myImageSource;
        myImageSource = CGImageSource.FromUrl (url, null);
        var ns = new NSDictionary ();
        var imageProperties = myImageSource.CopyProperties (ns, 0);
    var date = imageProperties [ImageIO.CGImageProperties.ExifSubsecTimeOrginal];
    var date2 = imageProperties [ImageIO.CGImageProperties.ExifDateTimeDigitized];
    var date3 = imageProperties [ImageIO.CGImageProperties.TIFFDateTime]; 

все они имеют значение null , но изображение имеет дату, когда я проверяю его с помощью библиотеки exif.

что не так?


person Nininea    schedule 18.10.2016    source источник


Ответы (1)


вот мое решение, не уверен, насколько оно идеально, но пока работает

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

            CGImageSource myImageSource;
            myImageSource = CGImageSource.FromUrl (url, null);
            var ns = new NSDictionary ();
            var imageProperties = myImageSource.CopyProperties (ns, 0);

            NSObject date = null;
            var exifDictionary = imageProperties.ValueForKey (ImageIO.CGImageProperties.ExifDictionary);
            if (exifDictionary != null) {
                date = exifDictionary.ValueForKey (ImageIO.CGImageProperties.ExifDateTimeOriginal);
            }
            takenDate = date != null ? DateTime.ParseExact (date.ToString (), "yyyy:MM:dd HH:mm:ss", null) : takenDate;
            return takenDate;
        } 
person Nininea    schedule 18.10.2016