UIImage send to email

我与影子孤独终老i 提交于 2019-12-24 10:55:56

问题


In my program modify an image at run time and I have to send it by e-mail. Not required to keep in the device. Any suggestions?

I use this but not works because the image is not saved in 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];

}


回答1:


You can use the UIImagePNGRepresentation() function to extract a png-formatted data from your UIImage.




回答2:


You can try this one. Image to be in:

UIImage *UIImageToSend;

And the code

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];
}


来源:https://stackoverflow.com/questions/9656478/uiimage-send-to-email

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!