【问题标题】:Get image taken date xamarin mac获取图像拍摄日期 xamarin mac
【发布时间】:2016-10-18 16:16:07
【问题描述】:

我需要在没有 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 库检查图像时,图像已拍摄日期。

什么不正确?

【问题讨论】:

    标签: exif cgimage xamarin.mac


    【解决方案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;
            } 
    

    【讨论】:

      猜你喜欢
      • 2012-12-06
      • 2013-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-23
      • 1970-01-01
      • 2023-03-30
      • 2013-03-20
      相关资源
      最近更新 更多