I am creating an Image Processing app that does two image analysis functions. One is to read the RGB data of the image and the other is to read the EXIF data. I am taking a photo with the front camera and then saving it to the documents folder. To grab the RGB values I load the image in this manner:
NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.jpg"];
UIImage *image = [UIImage imageWithContentsOfFile:jpgPath];
CFDataRef pixelData = CGDataProviderCopyData(CGImageGetDataProvider(image.CGImage));
const UInt8* data = CFDataGetBytePtr(pixelData);
This works as expected and I can get the pixel data. My issue is gathering the EXIF data. I am implementing the reading of my image in the same manner as RGB and all my EXIF data comes back as 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);
If I change the first line of code to read a preloaded image in the app like this:
NSString *aPath = [[NSBundle mainBundle] pathForResource:@"IMG_1406" ofType:@"JPG"];
It works. The problem is I can not preload the images. They must be taken live from the camera. Any suggestions are greatly appreciated. Thank you.