首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >获取照片日期xamarin mac

获取照片日期xamarin mac
EN

Stack Overflow用户
提问于 2016-10-18 16:16:07
回答 1查看 383关注 0票数 1

我需要在没有exif额外库的情况下获得图像拍摄日期,我在文档中发现的内容对我不起作用:

代码语言:javascript
复制
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]; 

所有这些都是空的,但是当我使用exif库检查它时,图像已经取了日期。

什么不对?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-10-18 17:28:58

这是我的解决方案,不知道它有多完美,但现在可行。

代码语言:javascript
复制
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;
        } 
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40113284

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档