UIImage发送到电子邮件

时间:2012-03-11 15:57:05

标签: xcode email uiimageview uiimage

在我的程序中,在运行时修改图像,我必须通过电子邮件发送它。不需要保留在设备中。有什么建议吗?

我使用此功能但不起作用,因为图像未保存在mi iphone =(

- (void)emailImage{


    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;

    // Set the subject of email
    [picker setSubject:@"MI FOTO FINAL"];

    // Fill out the email body text
    NSString *emailBody = @"Foto final";

    // This is not an HTML formatted email
    [picker setMessageBody:emailBody isHTML:NO];


    NSData *data = UIImagePNGRepresentation(Foto.image);

    [picker addAttachmentData:data  mimeType:@"image/png" fileName:@"ImagenFinal"];

  //  [picker addAttachmentData:data mimeType:nil fileName:nil];


    // Show email view  
    [self presentModalViewController:picker animated:YES];

}

2 个答案:

答案 0 :(得分:5)

你可以尝试这个。图片位于:

UIImage *UIImageToSend;

代码

MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
[composer setMailComposeDelegate:self];
if([MFMailComposeViewController canSendMail]) {
    [composer setToRecipients:[NSArray arrayWithObjects:@"JanJaap@Korteweg.nl",nil]];
    [composer setSubject:@"A nice subject"];
    [composer setMessageBody:@"Hi,\n\nI'm sending you this beautiful photograph." isHTML:NO];
    [composer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];

    NSData *data = UIImageJPEGRepresentation(UIImageToSend,1);
    [composer addAttachmentData:data  mimeType:@"image/jpeg" fileName:@"Photograph.jpg"];

   [self presentModalViewController:composer animated:YES];
}

答案 1 :(得分:2)

您可以使用UIImagePNGRepresentation()功能从UIImage中提取png格式的数据。