xcode UIImage 发送到电子邮件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9656478/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
UIImage send to email
提问by marduck19
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 =(
我使用这个但不起作用,因为图像没有保存在 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];
}
}
回答by Vincent
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:@"[email protected]",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];
}
回答by Alexander
You can use the UIImagePNGRepresentation()
function to extract a png-formatted data from your UIImage
.
您可以使用该UIImagePNGRepresentation()
函数从 .png 文件中提取 png 格式的数据UIImage
。