UIImagePickerController并从现有照片中提取EXIF数据众所周知,UIImagePickerController在选择后不会返回照片的元数据。但是,应用程序商店中的一些应用程序(Mobile Fotos,PixelPipe)似乎能够读取原始文件和存储在其中的EXIF数据,使应用程序能够从所选照片中提取地理数据。他们似乎是通过从/ private / var / mobile / Media / DCIM / 100APPLE /文件夹中读取原始文件并通过EXIF库运行它来完成此操作。但是,我无法找到一种方法来匹配从UIImagePickerController返回的照片到磁盘上的文件。我已经探索了文件大小,但原始文件是JPEG,而返回的图像是原始UIImage,因此无法知道所选图像的文件大小。我正在考虑制作一个哈希表并匹配每个图像的前x个像素。虽然这看起来有点过头了,但可能很慢。有什么建议?
3 回答
手掌心
TA贡献1942条经验 获得超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];
}}
缥缈止盈
TA贡献2041条经验 获得超4个赞
有一种方法 iOS 8
不使用任何第三方EXIF库。
#import <Photos/Photos.h>- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSURL *url = [info objectForKey:UIImagePickerControllerReferenceURL];
PHFetchResult *fetchResult = [PHAsset fetchAssetsWithALAssetURLs:@[url] options:nil];
PHAsset *asset = fetchResult.firstObject;
//All you need is
//asset.location.coordinate.latitude
//asset.location.coordinate.longitude
//Other useful properties of PHAsset
//asset.favorite
//asset.modificationDate
//asset.creationDate}- 3 回答
- 0 关注
- 606 浏览
添加回答
举报
0/150
提交
取消
