xamarin ios 屏幕截图和电子邮件 [英] xamarin ios screenshot and email
本文介绍了xamarin ios 屏幕截图和电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何截屏并通过按钮发送到电子邮件?截图的编码我已经做了,但是会保存到相册中.
How to take screenshot and send to a email with a button ? I have did the coding for taking screenshot, but it will saved to photo album.
partial void btnScreenshot (NSObject sender)
{
UIImage image;
UIGraphics.BeginImageContext (View.Frame.Size);
//new iOS 7 method to snapshot
View.DrawViewHierarchy (View.Frame, true);
image = UIGraphics.GetImageFromCurrentImageContext ();
UIGraphics.EndImageContext ();
//...code to save to photo album omitted for brevity
image.SaveToPhotosAlbum((img, err) => {
if(err != null)
Console.WriteLine("error saving image: {0}", err);
else
Console.WriteLine ("image saved to photo album");
UIAlertView alert = new UIAlertView("Screenshot", "Image saved successfully", alertDelegate, "OK", null);
alert.Show();
alert.Show();
});
}
推荐答案
你可以使用这个 Xamarin 教程 了解撰写电子邮件的说明.
You can use this Xamarin tutorial for instructions on composing the email.
然后添加截图需要使用AddAttachmentData
方法.
Then to add the screenshot, you need to use the AddAttachmentData
method.
// Take the screenshot
UIGraphics.BeginImageContext(View.Frame.Size);
View.DrawViewHierarchy(View.Frame, true);
UIImage image = UIGraphics.GetImageFromCurrentImageContext();
UIGraphics.EndImageContext();
// Don't save it to the album (unless you need to)
// Create an email
var _mailController = new MFMailComposeViewController();
_mailController.SetToRecipients(new []{"john@doe.com"});
_mailController.SetSubject("Send Screenshot");
_mailController.SetMessageBody("This is a screenshot of the app!", false);
// Add the screenshot as an attachment
_mailController.AddAttachmentData(image.AsPNG(),"image/png","Screenshot.png");
// Handle the action to take when the user completes sending the email
_mailController.Finished += ( object s, MFComposeResultEventArgs args) => {
System.Console.WriteLine (args.Result.ToString ());
args.Controller.DismissViewController (true, null);
};
// Show the email view
PresentViewController (_mailController, true, null);
这篇关于xamarin ios 屏幕截图和电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文