exif data in NSData image representation
I'm trying to create a PhoneGap plugin which uses AFFoundation to capture photos and return the image as base64 encoded string. This all works fine but the exif data seems to be missing from the returned image. Tried a few variations and got some pointers from other questions asked here but it still doesn't seem to work correctly. The current code is
NSMutableString *stringToReturn = [NSMutableString stringWithString: @""];
NSLog(@"about to request a capture from: %@", stillImageOutput);
[stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler:^(CMSampleBufferRef imageBuffer, NSError *error)
{
if (imageBuffer != NULL)
{
CFDictionaryRef exifAttachments = CMGetAttachment(imageBuffer, kCGImagePropertyExifDictionary, NULL);
CFMutableDictionaryRef mutable;
if (exifAttachments)
{
//
// Set orientation
//
mutable = CFDictionaryCreateMutableCo开发者_如何学Cpy(NULL, 0, exifAttachments);
int orientation = (int)[UIDevice currentDevice].orientation;
CFDictionaryAddValue(mutable, kCGImagePropertyOrientation, CFNumberCreate(NULL, kCFNumberIntType, &orientation));
CMSetAttachments(imageBuffer, mutable, kCMAttachmentMode_ShouldPropagate);
NSLog(@"attachements: %@", mutable);
}
//
// Get the image
//
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageBuffer];
[stringToReturn setString:[imageData base64EncodedString]];
//
// Call the success callback
//
[self performSelectorOnMainThread:@selector(doSuccessCallback:) withObject:[NSString stringWithString:stringToReturn] waitUntilDone:NO];
//
// Save it to the photo album
// It is done after we did the success callback to avoid accidental issues with
// the photo album stopping further processing
//
UIImage *image = [[UIImage alloc] initWithData:imageData];
UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
}
}];
Can anyone shed some light please? I seem to be completely stuck here.
精彩评论