UIImageView.Image for sending attachments using MonoTouch

I'm new to MonoTouch, and I'm trying to send an email with an image as an attachment, which the user will tame from the camera or select from the gallery.

I created the program and it works correctly (I have an image controller that loads the image from uiimagepicker into imageview. Then I call MFMailComposeViewController , but I don’t know how to transfer the image from the image to the addAttachmentdata method.

Suppose first I need to save an image from an image as a file, but I don’t know how to do this, and I can’t find documentation for it.

+4
source share
1 answer

First you need to turn UIImage into NSData , for example. using AsPNG or AsJPG , then use the correct MIME image for this. Here is 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 the attachment!", false); controller.PresentModalViewController (email, false); 

Note : "image.png" is the suggested file name specified for the recipient's email software (that is, it is not a local file on your device and should not correspond to anything that exists).

+4
source

Source: https://habr.com/ru/post/1394595/


All Articles