Search code examples
iphonescreenshot

iphone screenshot specific area


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 = UIGraphicsGetImageFromCurrentImageContext();
    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


Solution

  • 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();