获取简易的metaData较为容易,以下是测试图:
以下是本人提供的源码:
UIImage+MetaData.h
// // UIImage+MetaData.h // PictureInfo // // Created by YouXianMing on 14-8-27. // Copyright (c) 2014年 YouXianMing. All rights reserved. // #import <UIKit/UIKit.h> @interface UIImage (MetaData) - (NSDictionary *)JPEGmetaData; - (NSDictionary *)PNGmetaData; @end
UIImage+MetaData.h
// // UIImage+MetaData.m // PictureInfo // // Created by YouXianMing on 14-8-27. // Copyright (c) 2014年 YouXianMing. All rights reserved. // #import "UIImage+MetaData.h" #import <AssetsLibrary/AssetsLibrary.h> #import <ImageIO/ImageIO.h> @implementation UIImage (MetaData) - (NSDictionary *)JPEGmetaData { if (self == nil) { return nil; } // 转换成jpegData,信息要多一些 NSData *jpegData = UIImageJPEGRepresentation(self, 1.0); CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)jpegData, NULL); CFDictionaryRef imageMetaData = CGImageSourceCopyPropertiesAtIndex(source, 0, NULL); CFRelease(source); NSDictionary *metaDataInfo = CFBridgingRelease(imageMetaData); return metaDataInfo; } - (NSDictionary *)PNGmetaData { if (self == nil) { return nil; } NSData *pngData = UIImagePNGRepresentation(self); CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)pngData , NULL); CFDictionaryRef imageMetaData = CGImageSourceCopyPropertiesAtIndex(source, 0, NULL); CFRelease(source); NSDictionary *metaDataInfo = CFBridgingRelease(imageMetaData); return metaDataInfo; } @end
使用情况:
// // AppDelegate.m // GetPictureInfo // // Copyright (c) 2014年 Y.X. All rights reserved. // #import "AppDelegate.h" #import "UIImage+MetaData.h" @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. NSLog(@"%@", [[UIImage imageNamed:@"IMG_0151.JPG"] JPEGmetaData]); self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; return YES; } @end
以下是打印信息:
{
ColorModel = RGB;
Depth = 8;
Orientation = 1;
PixelHeight = 1936;
PixelWidth = 2592;
"{Exif}" = {
ColorSpace = 1;
PixelXDimension = 2592;
PixelYDimension = 1936;
};
"{JFIF}" = {
DensityUnit = 0;
JFIFVersion = (
1,
1
);
XDensity = 1;
YDensity = 1;
};
"{TIFF}" = {
Orientation = 1;
};
}
几个需要注意的地方:
1. 需要引入两个库
2. 一些需要注意的细节
你以为结束了么?没有呢,你还没取到图片的经纬度信息,对吧,一下给你提供资料自己去尝试:)
http://stackoverflow.com/questions/9766394/get-exif-data-from-uiimage-uiimagepickercontroller
How can we get Exif information from UIImage selected from UIImagePickerController? I had done much R&D for this and got many replies but still failed to implement this. I had gone through this this and this link Please help me to solve this problem. Thanks in advance..
|
||
5 Answers
Interesting question! I came up with the following solution working Import Then include the needed classes inside your .h-file:
And put this inside your
One thing I noticed is, that iOS will ask the user to allow location services – if he denies, you won‘t be abled to get the image data … EDIT Added code to save the image including its meta data. It‘s a quick approach, so maybe there is a better way, but it works!
|
|||||||||||||||||||||
|
accepted |
I had found solution and got answer from here From here We can get GPS info as well.. Amazing and thanks all for helping me to solve this problem. UPDATE This is another function that I had created myself, also return Exif
and We will retrieve that data like this
For all of this you should have to Import
|
||||||||||||||||||||
|
These answers all seem extremely complex. If the image has been saved
If you want to save that image from camera roll to another location (say in Sandbox/Documents) simply do:
|
|||||||||
|
You need ALAssetsLibrary to actually retrieve the EXIF info from an
|
|||
I have tried to insert GPS coordinates into image metadata picked by iPad Camera as it was suggested by Mehul. P.S.
... By supposing that you have already initializied somewhere locationManager in your code, like this:
and by importing CoreLocation/CoreLocation.h and ImageIO/ImageIO.h headers with associated frameworks. |