在应用程序中创建的电子邮件 jpg,包括元数据

发布于 2024-12-04 15:25:16 字数 574 浏览 3 评论 0原文

我已成功将元数据添加到应用程序内创建的 jpg 中,并使用该

writeImageToSavedPhotosAlbum: metadata: completionBlock: 

方法将其保存到相机胶卷中。不过,我还希望选择通过电子邮件发送此 jpg 以及元数据(例如位置、出口等)。我用它来发送电子邮件:

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
NSData *myData =  UIImageJPEGRepresentation(emailImage, 0.8);
[picker addAttachmentData:myData mimeType:@"image/jpg" fileName:@"photo"];

但是,这会导致没有元数据。
当通过 Apple 的照片应用程序发送保存的图像时,会包含元数据。 有没有办法将元数据嵌入到 NSData 附件中?有什么想法吗?

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

writeImageToSavedPhotosAlbum: metadata: completionBlock: 

method. However I would also like the option of emailing this jpg with the metadata (such as location, exit, etc.). I use this to email:

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
NSData *myData =  UIImageJPEGRepresentation(emailImage, 0.8);
[picker addAttachmentData:myData mimeType:@"image/jpg" fileName:@"photo"];

However, this results in no metadata.
When the saved image is sent via Apple's photo app, metadata is included.
Is there a way to embed the metadata into NSData attachment? Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

星光不落少年眉 2024-12-11 15:25:17

UIImage 不保存任何元数据。如果您有图像的路径,请直接从中读取数据。如果您从相机胶卷中获取图像,则可以使用 UIImagePickerDelegate 中的 imagePickerController:didFinishPickingMediaWithInfo: 方法,该方法还包含信息字典中的元数据。

mimeType 也应该是“image/jpeg”。

编辑:
要将元数据添加到UIImage,您可以使用 ImageIO框架:您可以从UIImage创建CGImageDestination对象,使用CGImageDestinationSetProperties向其添加元数据,然后获取原始数据(其中包括压缩图像和元数据)

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

鹤仙姿 2024-12-11 15:25:17

以下是将元数据附加到 NSMutableData 对象的示例代码,可以通过邮件发送。

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文