获取图像拍摄日期 xamarin mac

Get image taken date 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 库检查图像时,图像已经拍摄了日期。

哪里不对?

这是我的解决方案,不确定它有多完美,但现在可以使用

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;
        }