gpt4 book ai didi

iphone - 如何截取 View 的屏幕截图并通过电子邮件发送?

转载 作者:技术小花猫 更新时间:2023-10-29 10:47:29 24 4
gpt4 key购买 nike

我能否让我的应用截取 View 内容的屏幕截图并将其附加到电子邮件中?怎么办?

最佳答案

您可以将 View 转换为图像,然后可以用它创建电子邮件。

此代码 ( from here) 将允许您发送带有附件的电子邮件:

    - (void)emailImageWithImageData:(NSData *)data
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;

// Set the subject of email
[picker setSubject:@"Picture from my iPhone!"];

// Add email addresses
// Notice three sections: "to" "cc" and "bcc"
[picker setToRecipients:[NSArray arrayWithObjects:@"emailaddress1@domainName.com", @"emailaddress2@domainName.com", nil]];
[picker setCcRecipients:[NSArray arrayWithObject:@"emailaddress3@domainName.com"]];
[picker setBccRecipients:[NSArray arrayWithObject:@"emailaddress4@domainName.com"]];

// Fill out the email body text
NSString *emailBody = @"I just took this picture, check it out.";

// This is not an HTML formatted email
[picker setMessageBody:emailBody isHTML:NO];

// Attach image data to the email
// 'CameraImage.png' is the file name that will be attached to the email
[picker addAttachmentData:data mimeType:@"image/png" fileName:@"CameraImage"];

// Show email view
[self presentModalViewController:picker animated:YES];
//if you have a navigation controller: use that to present, else the user will not
//be able to tap the send/cancel buttons
//[self.navigationController presentModalViewController:picker animated:YES];


// Release picker
[picker release];
}

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
// Called once the email is sent
// Remove the email view controller
[self dismissModalViewControllerAnimated:YES];
}

要将您的 View 图形表示转换为图像,请使用代码 ( from here ):

UIGraphicsBeginImageContext(self.window.bounds.size);
[self.window.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData * data = UIImagePNGRepresentation(image);

[self emailImageWithImageData:data];

关于iphone - 如何截取 View 的屏幕截图并通过电子邮件发送?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6685169/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com