为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

慕虎7371278 2019-11-17 16:12:03
UIImagePickerController并从现有照片中提取EXIF数据众所周知,UIImagePickerController在选择后不会返回照片的元数据。但是,应用程序商店中的一些应用程序(Mobile Fotos,PixelPipe)似乎能够读取原始文件和存储在其中的EXIF数据,使应用程序能够从所选照片中提取地理数据。他们似乎是通过从/ private / var / mobile / Media / DCIM / 100APPLE /文件夹中读取原始文件并通过EXIF库运行它来完成此操作。但是,我无法找到一种方法来匹配从UIImagePickerController返回的照片到磁盘上的文件。我已经探索了文件大小,但原始文件是JPEG,而返回的图像是原始UIImage,因此无法知道所选图像的文件大小。我正在考虑制作一个哈希表并匹配每个图像的前x个像素。虽然这看起来有点过头了,但可能很慢。有什么建议?
查看完整描述

3 回答

?
长风秋雁

TA贡献1757条经验 获得超7个赞

这适用于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];
  }}



查看完整回答
反对 回复 2019-11-18
?
萧十郎

TA贡献1815条经验 获得超12个赞

有一种方法 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}



查看完整回答
反对 回复 2019-11-18
  • 3 回答
  • 0 关注
  • 350 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信