UIImageView.Image to mail attachment with MonoTouch

后端 未结 1 988
情书的邮戳
情书的邮戳 2021-01-20 02:42

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

相关标签:
1条回答
  • 2021-01-20 03:31

    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).

    0 讨论(0)
提交回复
热议问题