繁体   English   中英

如何获取ios中隐形部分的屏幕截图?

[英]How to get the screen shot of invisible part in ios?

我正在iOS应用程序上工作,我需要捕获视图并将MMS发送给特定的人,一切正常,但是我面临捕获不可见的问题(为澄清起见,我附加了图像)。

在此处输入图片说明

我正在查看可见的屏幕快照。如何解决问题? 有什么办法可以满足我的要求? 我得到的图像是

在此处输入图片说明

我用的代码来截图是

UIGraphicsBeginImageContext(webview_pdf.bounds.size);
[webview_pdf.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *pdfImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

好的建议是可取的。谢谢。

终于找到了解决办法

+ (UIImage *) imageFromWebView:(UIWebView *)view
{
    // tempframe to reset view size after image was created
    CGRect tmpFrame = view.frame;

    // set new Frame
    CGRect aFrame = view.frame;
    aFrame.size.height = [view sizeThatFits:[[UIScreen mainScreen] bounds].size].height;
    view.frame = aFrame;

    // do image magic
    UIGraphicsBeginImageContext([view sizeThatFits:[[UIScreen mainScreen] bounds].size]);

    CGContextRef resizedContext = UIGraphicsGetCurrentContext();
    [view.layer renderInContext:resizedContext];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    // reset Frame of view to origin
    view.frame = tmpFrame;
    return image;
}

您需要创建另一个视图,它是内容的全部大小。 您可以在屏幕外添加此视图,然后以与此处相同的方式捕获它。 之所以将其切除,是因为视图仅呈现了该部分内容。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM