我只是想知道是否有办法获取图片的时间戳,或者该信息是否甚至被写入图像文件,例如从拍摄时间开始。
提前致谢
导入 imageIO 框架并尝试使用带有时间戳的图像。这是一个,将其添加到您的项目中。
#import <ImageIO/ImageIO.h>
NSString *path = [[NSBundle mainBundle] pathForResource:@"gg_gps" ofType:@"jpg"];
NSURL *imageFileURL = [NSURL fileURLWithPath:path];
CGImageSourceRef imageSource = CGImageSourceCreateWithURL((CFURLRef)CFBridgingRetain(imageFileURL), NULL);
// or you can get your imageSource this other way:
// NSData *data = [NSData dataWithContentsOfFile:path];
// CGImageSourceRef imageSource = CGImageSourceCreateWithData((__bridge CFDataRef)data, NULL);
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:NO], (NSString *)kCGImageSourceShouldCache, nil];
CFDictionaryRef imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, (CFDictionaryRef)CFBridgingRetain(options));
CFDictionaryRef exifDic = CFDictionaryGetValue(imageProperties, kCGImagePropertyExifDictionary);
if (exifDic){
NSString *timestamp = (NSString *)CFBridgingRelease(CFDictionaryGetValue(exifDic, kCGImagePropertyExifDateTimeOriginal));
if (timestamp){
NSLog(@"timestamp: %@", timestamp);
} else {
NSLog(@"timestamp not found in the exif dic %@", exifDic);
}
} else {
NSLog(@"exifDic nil for imageProperties %@",imageProperties);
}
CFRelease(imageProperties);