gpt4 book ai didi

ios - 截图并以编程方式发送

转载 作者:可可西里 更新时间:2023-11-01 05:54:23 25 4
gpt4 key购买 nike

当用户点击我的应用程序中的按钮时,我想截取当前 View 的屏幕截图并打开一 strip 有该屏幕截图图像作为附件的文本消息。我如何在 iOS7 中执行此操作?

(我看过关于如何截取屏幕截图的帖子,但没有看到有关截取屏幕截图并将其附加到消息中的任何内容)

谢谢!

最佳答案

1. 要截图添加QuartzCore框架,可以使用UIGraphicsBeginImageContextWithOptions

UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0);
[self.myView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *theImage=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

NSData *theImageData=UIImageJPEGRepresentation(theImage, 1.0 ); //you can use PNG too

2. 要在邮件中附加此图像,请在构建阶段添加 MessageUI 框架。并使用此 NSData 进行附加,类似这样

//Check if mail can be sent
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;

// Add NSData you got as screenshot to attachment
[mailer addAttachmentData:theImageData mimeType:@"image/jpeg" fileName:[NSString stringWithFormat:@"test.jpg"]];
[self presentModalViewController:mailer animated:YES];

}

编辑:

3.通过短信发送图片

    // Will Work only for iOS 7

MFMessageComposeViewController* messageComposer = [[MFMessageComposeViewController alloc] init];
messageComposer.messageComposeDelegate = self; // As mentioned by the OP in comments, we have to set messageComposeDelegate to self.
messageComposer.recipients = [NSArray arrayWithObject:@"123456789"];

if([MFMessageComposeViewController canSendText])
{

if([MFMessageComposeViewController respondsToSelector:@selector(canSendAttachments)] && [MFMessageComposeViewController canSendAttachments])
{
NSString* uti = (NSString*)kUTTypeMessage;
[messageComposer addAttachmentData:theImageData typeIdentifier:uti filename:@"filename.jpg"];
}

[self presentViewController:messageComposer animated:YES completion:nil];
}

处理来自 MFMessageComposeViewController 的委托(delegate)回调

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{

}

关于ios - 截图并以编程方式发送,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22371525/

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