UIImage send to email

2019-07-29 22:16发布

问题:

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