Email jpg created in app including metadata

倾然丶 夕夏残阳落幕 提交于 2019-11-30 10:36:50

UIImage doesn't hold any metadata. If you have the path for the image read data directly from it. If you get the image back from camera roll there's the imagePickerController:didFinishPickingMediaWithInfo: method from UIImagePickerDelegate which also contains the metadata inside the info dictionary.

Also the mimeType should be "image/jpeg".

Edit: To add metadata to a UIImage you can use the ImageIO framework: You can create a CGImageDestination object from a UIImage, add metadata to it using CGImageDestinationSetProperties and then get the raw data (which includes the compressed image and the metadata) from it

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!