iOS将UIImageView附加到电子邮件中

时间:2014-06-24 19:40:16

标签: ios uiimageview email-attachments

我正在开发一个将信息发送到电子邮件的应用。我有一个按钮,按下它时会显示库中或相机中的图像选择。一旦选择了图像,它就会在UIImageView中显示它。如果"发送报告'然后如何将该图像从UIImageView附加到电子邮件中。按钮被按下了吗?

以下是我尝试加载的代码:

// Attach an image to the email.
        NSString *path = [[NSBundle mainBundle] pathForResource:@"ipodnano" ofType:@"png"];
        NSData *myData = [NSData dataWithContentsOfFile:path];
        [picker addAttachmentData:myData mimeType:@"image/png" fileName:@"ipodnano"];

但是,我无法解决如何从UIImageView附加我的图像的问题。 UIImageView称为imageView。

2 个答案:

答案 0 :(得分:2)

NSData *imageData = UIImagePNGRepresentation([imageView image]);
[picker addAttachmentData:imageData mimeType:@"image/png" fileName:@"ipodnano"];

答案 1 :(得分:1)

查看MFMailComposeViewController

它有方法addAttachmentData:mimeType:fileName:。所以你需要把你的图像作为NSData。