获取拍摄日期Xamarin Mac [英] Get image taken date xamarin mac

查看:103
本文介绍了获取拍摄日期Xamarin Mac的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在没有exif额外库的情况下获取图像拍摄日期,而我在文档中找不到这些库:

I need to get image taken date without exif extra libraries, what I found in documentations, doesn't work for me :

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库检查图像时,图像已经拍摄了日期.

all of them is null , but image has taken date, when I check it with exif library.

什么是不正确的?

推荐答案

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

here is my solution, not sure how perfect it is , but works for now

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

这篇关于获取拍摄日期Xamarin Mac的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆