开发者

iphone screenshot specific area

开发者 https://www.devze.com 2023-01-08 16:19 出处:网络
I have a View including a Toolbar and a WebView UIVIEW UIToolbar UIWebview Now i like to make a screenshot ONLY from the WebView with:

I have a View including a Toolbar and a WebView

UIVIEW
  UIToolbar
  UIWebview

Now i like to make a screenshot ONLY from the WebView with:

    UIGraphicsBeginImageContext(articleWebView.window.bounds.size);     
    [articleWebView.window.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *screenImage = UIGraphic开发者_运维知识库sGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

But always ImageCapture starts from the TOP of the Screen. So it includes the Toolbar (even 20 empty pixel at the top from the Statusbar)

How can I just capture the Image thats actual in my UIWebView?

Thanks Chris


Your UIWebView is backed by its own layer, so you should be able to just grab the currently displayed contents for it:

UIGraphicsBeginImageContext(articleWebView.bounds.size);     
[articleWebView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
0

精彩评论

暂无评论...
验证码 换一张
取 消