我正在創建一個圖像處理應用程序,它可以執行兩種圖像分析功能。一種是讀取圖像的RGB數據,另一種是讀取EXIF數據。我正在使用前置攝像頭拍照,然後將其保存到文檔文件夾中。爲了獲取RGB值,我以這種方式加載圖像:iPhone EXIF數據不會從文檔文件夾中讀取
NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.jpg"];
UIImage *image = [UIImage imageWithContentsOfFile:jpgPath];
CFDataRef pixelData = CGDataProviderCopyData(CGImageGetDataProvider(image.CGImage));
const UInt8* data = CFDataGetBytePtr(pixelData);
這工作正常,我可以得到像素數據。我的問題是收集EXIF數據。我以與RGB相同的方式實現讀取圖像,並且所有EXIF數據都返回爲NULL。
NSString *EXIFPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.jpg"];
NSURL *url = [NSURL fileURLWithPath:EXIFPath];
CGImageSourceRef sourceRef = CGImageSourceCreateWithURL((__bridge CFURLRef)url, NULL);
NSDictionary *immutableMetadata = (__bridge NSDictionary *) CGImageSourceCopyPropertiesAtIndex(sourceRef,0,NULL);
NSDictionary *exifDic = [immutableMetadata objectForKey:(NSString *)kCGImagePropertyExifDictionary];
NSNumber *ExifApertureValue = [exifDic objectForKey:(NSString*)kCGImagePropertyExifApertureValue];
NSNumber *ExifShutterSpeed = [exifDic objectForKey:(NSString*)kCGImagePropertyExifShutterSpeedValue];
NSLog(@"ExifApertureValue : %@ \n",ExifApertureValue);
NSLog(@"ExifShutterSpeed : %@ \n",ExifShutterSpeed);
如果我改變的第一行代碼在這樣的應用讀取預加載圖像:
NSString *aPath = [[NSBundle mainBundle] pathForResource:@"IMG_1406" ofType:@"JPG"];
它的工作原理。問題是我無法預載圖像。他們必須從相機中帶電。任何建議,非常感謝。謝謝。
從這裏 http://stackoverflow.com/questions/1238838/uiimagepickercontroller-and-獲取答案提取exif數據從現有的照片 – 2012-04-09 07:26:18
請參閱http://stackoverflow.com/questions/9766394/get-exif-data-from-uiimage-uiimagepickercontroller/9890442#9890442 – 2012-04-09 07:38:19
我有代碼將讀取EXIF數據,而不是當圖像在手機的Document文件夾中時。有沒有辦法解決它如何讀取圖像而不是重寫所有的EXIF代碼? – tguidon 2012-04-09 15:32:07