UIImagePickerController并从现有照片中提取EXIF数据

UIImagePickerController并从现有照片中提取EXIF数据

众所周知,UIImagePickerController在选择后不会返回照片的元数据。但是,应用程序商店中的一些应用程序(Mobile Fotos,PixelPipe)似乎能够读取原始文件和存储在其中的EXIF数据,使应用程序能够从所选照片中提取地理数据。

他们似乎是通过从/ private / var / mobile / Media / DCIM / 100APPLE /文件夹中读取原始文件并通过EXIF库运行它来完成此操作。

但是,我无法找到一种方法来匹配从UIImagePickerController返回的照片到磁盘上的文件。我已经探索了文件大小,但原始文件是JPEG,而返回的图像是原始UIImage,因此无法知道所选图像的文件大小。

我正在考虑制作一个哈希表并匹配每个图像的前x个像素。虽然这看起来有点过头了,但可能很慢。

有什么建议?


慕虎7371278
浏览 361回答 3
3回答

长风秋雁

这适用于iOS5(beta 4)和相机胶卷(你需要为.h中的块输入defs):-(void) imagePickerController:(UIImagePickerController *)picker             didFinishPickingMediaWithInfo:(NSDictionary *)info{   NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];   if ([mediaType isEqualToString:(NSString*)kUTTypeImage]) {     NSURL *url = [info objectForKey:UIImagePickerControllerReferenceURL];     if (url) {       ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset) {       CLLocation *location = [myasset valueForProperty:ALAssetPropertyLocation];       // location contains lat/long, timestamp, etc       // extracting the image is more tricky and 5.x beta ALAssetRepresentation has bugs!     };     ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror) {       NSLog(@"cant get image - %@", [myerror localizedDescription]);     };     ALAssetsLibrary *assetsLib = [[ALAssetsLibrary alloc] init];     [assetsLib assetForURL:url resultBlock:resultblock failureBlock:failureblock];   }}

萧十郎

有一种方法&nbsp;iOS 8不使用任何第三方EXIF库。#import&nbsp;<Photos/Photos.h>-&nbsp;(void)imagePickerController:(UIImagePickerController&nbsp;*)picker&nbsp;didFinishPickingMediaWithInfo:(NSDictionary&nbsp;*)info&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;NSURL&nbsp;*url&nbsp;=&nbsp;[info&nbsp;objectForKey:UIImagePickerControllerReferenceURL]; &nbsp;&nbsp;&nbsp;&nbsp;PHFetchResult&nbsp;*fetchResult&nbsp;=&nbsp;[PHAsset&nbsp;fetchAssetsWithALAssetURLs:@[url]&nbsp;options:nil]; &nbsp;&nbsp;&nbsp;&nbsp;PHAsset&nbsp;*asset&nbsp;=&nbsp;fetchResult.firstObject; &nbsp;&nbsp;&nbsp;&nbsp;//All&nbsp;you&nbsp;need&nbsp;is &nbsp;&nbsp;&nbsp;&nbsp;//asset.location.coordinate.latitude &nbsp;&nbsp;&nbsp;&nbsp;//asset.location.coordinate.longitude &nbsp;&nbsp;&nbsp;&nbsp;//Other&nbsp;useful&nbsp;properties&nbsp;of&nbsp;PHAsset &nbsp;&nbsp;&nbsp;&nbsp;//asset.favorite &nbsp;&nbsp;&nbsp;&nbsp;//asset.modificationDate &nbsp;&nbsp;&nbsp;&nbsp;//asset.creationDate}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python