我需要在没有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]; 所有这些都是空的,但是当我使用exif库检查它时,图像已经取了日期。
什么不对?
发布于 2016-10-18 17:28:58
这是我的解决方案,不知道它有多完美,但现在可行。
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;
} https://stackoverflow.com/questions/40113284
复制相似问题