在我的iOS应用中,我允许用户从相册中选择图像或从相机中捕获图像。紧接着,我提出了一个MFMailComposeViewController,其中选定/捕获的图像作为附件。
图像已正确附加并发送,但电子邮件的照片缩略图预览区域在所有情况下均为空白,除非选择了相册中的最新照片。如果拍摄了图像或从相册中选择了旧图像,则它是空白的,如下所示:
我附加捕获/选定图像的代码是:
MFMailComposeViewController email = new MFMailComposeViewController ();
email.SetToRecipients(new string[] {"test@test.com"});
email.SetSubject("Photo for " + CurrentCompany.DbaName + " (" + CurrentCompany.CoKey.ToString() + ")");
//imageToEmail is a UIImage that is set in the callback from the image capture/selection process
email.AddAttachmentData (imageToEmail.AsPNG(), "image/png", "photo.png");
email.Finished += HandleFinished;
NavigationController.PresentViewController(email, true, null);
为什么预览空白?
答案 0 :(得分:0)
试试这个:
email.AddAttachmentData (imageToEmail.AsPNG(), "image/png", "photo.png");
将此行替换为:
NSData *data = UIImagePNGRepresentation(imageToEmail);//Your uiimage convert to nsdata
[email addAttachmentData:data mimeType:@"image/png" fileName:@"Myphoto"];
答案 1 :(得分:0)
如果将来有人遇到这种情况,我尝试了几种不同的方法来保存UIImage(应用程序的个人存储位置,相册等),但没有一种方法可以将图像作为PNG附加。将UIImage保存为JPEG是我修复它的原因。改变这一行:
email.AddAttachmentData (imageToEmail.AsPNG(), "image/png", "photo.png");
为:
email.AddAttachmentData (imageToEmail.AsJPEG(), "image/jpg", "photo.jpg");
允许所有捕获或选定的图像在电子邮件中显示预览缩略图。