【发布时间】:2011-03-04 05:13:49
【问题描述】:
我想知道是否有人知道在打开邮件应用程序时如何在电子邮件正文中使用图像。有人可以帮忙吗?
在此先感谢基兰。
【问题讨论】:
我想知道是否有人知道在打开邮件应用程序时如何在电子邮件正文中使用图像。有人可以帮忙吗?
在此先感谢基兰。
【问题讨论】:
NSData *photoData = UIImageJPEGRepresentation([UIImage imageNamed:@"qwerty.png"], 1);
MFMailComposeViewController *viewController = [[MFMailComposeViewController alloc] init];
[viewController addAttachmentData:photoData mimeType:@"image/jpg" fileName:[NSString stringWithFormat:@"photo.png"]];
我是手工编写的代码,所以可能会有一些错误,但你应该明白大致的想法。
【讨论】:
您可以使用 base64 编码在邮件正文中附加图像
MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
NSData *imageData = UIImageJPEGRepresentation(image, 0.8);
NSString *imageStr = [imageData base64EncodingWithLineLength:[imageData length]];
NSString *htmlStr = [NSString stringWithFormat:@".....<img src='data:image/jpeg;base64,%@'>.......",imageStr];
[mailComposer setMessageBody:htmlStr isHTML:YES];
[self presentModalViewController:mailComposer animated:YES];
[mailComposer release];
【讨论】: