繁体   English   中英

如何从照片中获取exif?

[英]how to get exif from photo?

我想从图片中获取exif。 我怎么做到最佳?

NSData *dataOfImageFromGallery = UIImageJPEGRepresentation (workingImage,0.5);

CGImageSourceRef imageSource;
imageSource = CGImageSourceCreateWithData((__bridge CFDataRef)dataOfImageFromGallery, NULL);

if (imageSource == NULL) { 
    // Error loading image ... 
     return; } 

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool:NO], (NSString *)kCGImageSourceShouldCache, nil]; 
CFDictionaryRef imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, (__bridge CFDictionaryRef)options); 

if (imageProperties) { 
    NSNumber *width = (__bridge NSNumber *)CFDictionaryGetValue(imageProperties, kCGImagePropertyPixelWidth); 
    NSNumber *height = (__bridge NSNumber *)CFDictionaryGetValue(imageProperties, kCGImagePropertyPixelHeight); 

    CFRelease(imageProperties); 

    NSLog(@"width: %@", width);
    NSLog(@"height: %@", height);  
}

这个打印widthheight但在ImageIO.h库文件中的CGImageProperties.h中EXIF属性大约为40,我不知道如何一次打印所有。

使用exiftool,我的基于exiftool的简单项目

如果您的目标是IOS 4及更高版本,则应使用ALAssetsLibrary。 这里有很多线程描述了ALAssetsLibrary以及如何从图像中获取EXIF数据。

但请注意,如果用户不允许您的APP ALAssetsLibrary的位置服务将无法工作,并将报告错误(访问被拒绝)

如果您只想记录imageProperties字典的全部内容,那么只需执行以下操作:

NSLog(@"imageProperties: %@", imageProperties);

如果那不是您想要的,请澄清您的问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM