UIImageView.Image通过MonoTouch邮件附件 [英] UIImageView.Image to mail attachment with MonoTouch

查看:90
本文介绍了UIImageView.Image通过MonoTouch邮件附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是MonoTouch的新手,我正在尝试发送一封带有图片的电子邮件作为附件,用户可以从相机上对其进行驯服或从画廊中进行挑选.

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.

我已经创建了程序,并且程序可以正常运行(我有一个imageview控制器,它将图像从uiimagepicker加载到imageview.然后我调用MFMailComposeViewController,但是我不知道如何将图像从imageview传递到addAttachmentdata方法.

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.

我想首先我必须将imageview中的图像另存为文件,但是我不知道该怎么办,也找不到文档.

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.

推荐答案

首先,您需要将UIImage变成NSData,例如使用AsPNGAsJPG,然后为图像使用正确的 MIME 类型.这是一个示例:

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

注意:"image.png"

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

这篇关于UIImageView.Image通过MonoTouch邮件附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆