UIImageView.Image to mail attachment with MonoTouch

痞子三分冷 提交于 2019-12-04 03:45:31

问题


I am new to MonoTouch and I am trying to send an email with an image as attachment that a user will tame from camera or pick from gallery.

I have created the program and it runs correctly (I have an imageview controller which loads an image from uiimagepicker to imageview. Then I call MFMailComposeViewController but I don't know how to pass the image from imageview to addAttachmentdata method.

I suppose first I have to save the image from imageview as a file but I don't know how to do it and I can't find documentation for it.


回答1:


First you need to turn the UIImage into an NSData, e.g. using AsPNG or AsJPG, then use the right MIME type for the image. Here's an example:

MFMailComposeViewController email = new MFMailComposeViewController ();
// any UIImage will do
UIImage img = UIImage.FromFile (".../anyimage.png");
email.AddAttachmentData (img.AsPNG (), "image/png", "image.png");
email.SetSubject ("Photo from my iPhone");
email.SetMessageBody ("Here's the attachment!", false);
controller.PresentModalViewController (email, false);

Note: the "image.png" is a suggested file name given to the recipient email software (i.e. it's not a local file in your device and does not need to match anything that exists).



来源:https://stackoverflow.com/questions/9128124/uiimageview-image-to-mail-attachment-with-monotouch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!