UIImagePickerController 并从现有照片中提取 EXIF 数据 [英] UIImagePickerController and extracting EXIF data from existing photos

查看:28
本文介绍了UIImagePickerController 并从现有照片中提取 EXIF 数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

It's well known that UIImagePickerController doesn't return the metadata of the photo after selection. However, a couple of apps in the app store (Mobile Fotos, PixelPipe) seem to be able to read the original files and the EXIF data stored within them, enabling the app to extract the geodata from the selected photo.

他们似乎通过从 /private/var/mobile/Media/DCIM/100APPLE/ 文件夹中读取原始文件并通过 EXIF 库运行它来做到这一点.

They seem to do this by reading the original file from the /private/var/mobile/Media/DCIM/100APPLE/ folder and running it through an EXIF library.

但是,我无法找到将 UIImagePickerController 返回的照片与磁盘上的文件进行匹配的方法.我研究了文件大小,但原始文件是 JPEG,而返回的图像是原始 UIImage,因此无法知道所选图像的文件大小.

However, I can't work out a way of matching a photo returned from the UIImagePickerController to a file on disk. I've explored file sizes, but the original file is a JPEG, whilst the returned image is a raw UIImage, making it impossible to know the file size of the image that was selected.

我正在考虑制作一个哈希表并与每个图像的前 x 个像素进行匹配.不过,这似乎有点过头了,而且可能很慢.

I'm considering making a table of hashes and matching against the first x pixels of each image. This seems a bit over the top though, and probably quite slow.

有什么建议吗?

推荐答案

顽皮的做法是遍历 UIImagePickerViewController 的视图并在委托回调中挑选出选中的图像.

The naughty way to do this is to traverse the UIImagePickerViewController's views and pick out the selected image in the delegate callback.

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

  id thumbnailView = [[[[[[[[[[picker.view subviews] 
                  objectAtIndex:0] subviews]
                  objectAtIndex:0] subviews]
                objectAtIndex:0] subviews]
                objectAtIndex:0] subviews]
              objectAtIndex:0];

  NSString *fullSizePath = [[[thumbnailView selectedPhoto] fileGroup] pathForFullSizeImage];
  NSString *thumbnailPath = [[[thumbnailView selectedPhoto] fileGroup] pathForThumbnailFile];

  NSLog(@"%@ and %@", fullSizePath, thumbnailPath);

}

这将为您提供全尺寸图像的路径,然后您可以使用您选择的 EXIF 库打开该图像.

That will give you the path to the full size image, which you can then open with an EXIF library of your choice.

但是,这会调用私有 API,如果您提交此应用程序,Apple 将检测到这些方法名称.所以不要这样做,好吗?

But, this calls a Private API and these method names will be detected by Apple if you submit this app. So don't do this, OK?

这篇关于UIImagePickerController 并从现有照片中提取 EXIF 数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆