将图像附加到电子邮件? [英] Attaching an image to an email?

查看:139
本文介绍了将图像附加到电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用MFMailComposeViewController发送电子邮件,我已经有了这个设置,但我实际上无法将图片(屏幕截图)附加到电子邮件中。

I want to to use MFMailComposeViewController to send an email, and I already have that set up, but I'm having trouble actually attaching an image, which is a screenshot, into the email.

这是代码行。

[composer addAttachmentData:image mimeType:image/png //png undeclared//fileName:@"GameOver Screenshot.png"]; //Incompatible Obj-C types 'struct UIImage *' expected 'struct NSData *' when passing argument 1 of .....//

image是我的UIImage截图的名称。我不知道该替换它。

image is the name of my UIImage screenshot. I'm not sure what to replace it with.

提前感谢您的帮助/协助。

Thanks in advance for the help/assistance.

推荐答案

addAttachmentData的第一个参数是附件的NSData。如果你的图片是UIImage,那么试试这个:

The first parameter to addAttachmentData is an NSData of the attachment. If your image is a UIImage, then try this:

NSData *data = UIImagePNGRepresentation(image);
[composer addAttachmentData:data 
                   mimeType:@"image/png" 
                   fileName:@"GameOver Screenshot.png"];

这篇关于将图像附加到电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆