我需要在没有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库检查时,图像已经采用了日期。
什么是不正确的?
答案 0 :(得分: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;
}