Email jpg created in app including metadata

前端 未结 2 1446
天涯浪人
天涯浪人 2021-01-01 07:52

I have successfully added metadata to a jpg created within the app and saved it to the Camera Roll using the

writeImageToSavedPhotosAlbum: metadata: complet         


        
2条回答
  •  太阳男子
    2021-01-01 08:44

    Here is an example code to attach metadata to a NSMutableData object, which can be mailed.

    UIImage* yourImage = ... from somewhere ...
    NSDictionary* info = ... in my case from didFinishPickingMediaWithInfo:
    
    CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef) UIImageJPEGRepresentation(yourImage, 0.5 /* compression factor */), NULL);
    
    NSMutableData* imageData = [NSMutableData data];
    
    CGImageDestinationRef imageDest = CGImageDestinationCreateWithData((__bridge CFMutableDataRef)imageData, kUTTypeJPEG, 1, NULL);
    CGImageDestinationAddImageFromSource(imageDest, source, 0, (__bridge CFDictionaryRef)info[@"UIImagePickerControllerMediaMetadata"]);
    CGImageDestinationFinalize(imageDest);
    
    CFRelease(imageDest);
    CFRelease(source);
    
    // at this point, imageData will contain your image + metadata
    

提交回复
热议问题