gpt4 book ai didi

objective-c - 从图像获取“时间戳”

转载 作者:行者123 更新时间:2023-12-01 17:43:52 25 4
gpt4 key购买 nike

我只是想知道是否有一种获取图片时间戳的方法,或者该信息是否甚至写入到图像文件中(例如从拍摄时开始)。

提前致谢

最佳答案

导入imageIO框架并尝试使用带有时间戳的图像。这是one,将其添加到您的项目中。

#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);

关于objective-c - 从图像获取“时间戳”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11843778/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com