我使用MessageUI框架在使用UIImagePickerController拍摄照片后通过电子邮件发送和图像。当我拍摄照片然后调用邮件邮件界面时,我得到了撰写窗口。在iPod touch(iOS 4.3.5)和iPad(iOS 5.0.1)上进行测试时,我会在撰写窗口的主体中看到图像附件。在iPhone(4S iOS 5.0.1)上进行测试时,图像不会出现在撰写窗口中,而是会看到一个图像附件大小的框,其中嵌入了一个带有“?”的蓝色小框。在它。
在发送邮件的两种情况下,图像都会显示在邮件应用程序 - iOS设备和Mac中收到的邮件中。
我该怎么做才能解决这个问题?
更新:我通过改变来解决这个问题:
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(imageToSend)]
为:
NSData *imageDataJPG = [NSData dataWithData:UIImageJPEGRepresentation(imageToSend, 1.0)];
我无法在UIKit文档中看到UIImagePNGRepresentation中有任何内容无法在iPhone上运行...
(Xcode 4.2.1,ARC,5.0 SDK,Deploy target 4.3)
以下是撰写邮件的代码:
-(void)displayComposerSheet
{
MFMailComposeViewController *mailPicker = [[MFMailComposeViewController alloc] init];
mailPicker.mailComposeDelegate = self;
[mailPicker setSubject:@"Photo"];
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(imageToSend)];
[mailPicker addAttachmentData:imageData mimeType:@"image/png" fileName:@"Photo"];
// Fill out the email body text.
NSString *line1 = [NSString stringWithFormat: @"I took this photo on my %@.\n", [[UIDevice currentDevice] model]];
NSString *body = [NSString stringWithFormat:@"%@", line1];
[mailPicker setMessageBody:body isHTML:NO];
// Present the mail composition interface.
[self presentModalViewController:mailPicker animated:YES];
[mailPicker setSubject:@"Photo"];
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(imageToSend)];
[mailPicker addAttachmentData:imageData mimeType:@"image/png" fileName:@"Photo"];
// Fill out the email body text.
NSString *line1 = [NSString stringWithFormat: @"I took this photo on my %@.\n", [[UIDevice currentDevice] model]];
NSString *body = [NSString stringWithFormat:@"%@", line1];
[mailPicker setMessageBody:body isHTML:NO];
// Present the mail composition interface.
[self presentModalViewController:mailPicker animated:YES];
答案 0 :(得分:1)
图像尺寸受到限制,因此如果您发送的图像大于某个尺寸,您将获得上述效果。
我查看了自己的代码,看到我有
#define MAX_MAIL_DIM 1536
似乎是1024 * 1.5。对不起,我不记得我是怎么到达那个号码的,但我怀疑这是反复试验。
答案 1 :(得分:1)
larik,您对使用JPEG作为数据类型的建议非常有用。无论如何,这个大小的PNG文件太大了 - 大约10MB。这是带有JPEG NSData的代码:
if ([MFMailComposeViewController canSendMail]) {
picker = [[MFMailComposeViewController alloc] init];
[picker setMailComposeDelegate:self];
[picker setSubject:@"My Picture"];
NSString *emailBody = @"";
[picker setMessageBody:emailBody isHTML:YES];
NSData *data = UIImageJPEGRepresentation(tempImage, 0);
[picker addAttachmentData:data mimeType:@"image/jpg" fileName:@"CameraImage"];
}