在应用程序中创建的电子邮件 jpg,包括元数据
我已成功将元数据添加到应用程序内创建的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
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 aCGImageDestination
object from a UIImage, add metadata to it usingCGImageDestinationSetProperties
and then get the raw data (which includes the compressed image and the metadata) from it以下是将元数据附加到 NSMutableData 对象的示例代码,可以通过邮件发送。
Here is an example code to attach metadata to a NSMutableData object, which can be mailed.