开发者

exif data in NSData image representation

开发者 https://www.devze.com 2023-04-11 11:41 出处:网络
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 retu

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号