应用内屏幕截图并附加到电子邮件,无需保存到库中

发布于 2024-11-16 22:07:52 字数 104 浏览 1 评论 0原文

我想知道如果我想让我的应用程序能够通过按 UI 按钮来截取屏幕截图并立即弹出并通过邮件撰写和通过电子邮件发送屏幕截图而不将其保存到照片库中,我想知道应该使用什么代码?

非常感谢!

I would like to know what code should i use if i want to make my app able to take a screenshot of the screen by pressing a UIbutton and immediately pop up and Mail compose and email out the screenshot without saving it into photo library?

Many thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

莳間冲淡了誓言ζ 2024-11-23 22:07:52

您需要向项目中添加两个框架 - QuartzCoreMessageUI,然后执行 #import 和 <代码>#import

你的按钮按下代码应该是这样的,

- (void)buttonPress:(id)sender
{
    UIGraphicsBeginImageContext(self.view.frame.size);
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    NSData * imageData = UIImageJPEGRepresentation(image, 1.0);

    if ( [MFMailComposeViewController canSendMail] ) {
        MFMailComposeViewController * mailComposer = [[[MFMailComposeViewController alloc] init] autorelease];
        mailComposer.delegate = self;
        [mailComposer addAttachmentData:imageData mimeType:@"image/jpeg" fileName:@"attachment.jpg"];

        /* Configure other settings */

        [self presentModalViewController:mailComposer animated:YES];
    }
}

You will need to add two frameworks to your project - QuartzCore and MessageUI and then do #import <QuartzCore/QuartzCore.h> and #import <MessageUI/MessageUI.h>.

Your button press code should be like,

- (void)buttonPress:(id)sender
{
    UIGraphicsBeginImageContext(self.view.frame.size);
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    NSData * imageData = UIImageJPEGRepresentation(image, 1.0);

    if ( [MFMailComposeViewController canSendMail] ) {
        MFMailComposeViewController * mailComposer = [[[MFMailComposeViewController alloc] init] autorelease];
        mailComposer.delegate = self;
        [mailComposer addAttachmentData:imageData mimeType:@"image/jpeg" fileName:@"attachment.jpg"];

        /* Configure other settings */

        [self presentModalViewController:mailComposer animated:YES];
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文