Take snapshot / screenshot of UIWebView
How do I take a snapsho开发者_C百科t / screenshot of the UIWebView
control?
The accepted answer is correct, however the screenshot is not in retina resolution.
Using UIGraphicsBeginImageContextWithOptions
and set its scale parameter 0.0f makes it capture in native resolution.
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
CGRect rect = [keyWindow bounds];
UIGraphicsBeginImageContextWithOptions(rect.size,YES,0.0f);
CGContextRef context = UIGraphicsGetCurrentContext();
[keyWindow.layer renderInContext:context];
UIImage *capturedScreen = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Use This:
UIGraphicsBeginImageContext(rect.size);
[webView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
use this code to take a screenshot and save it to the library
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, self, nil, nil);
you can change the screenshot taking portion by changing the
UIGraphicsBeginImageContext(self.view.bounds.size);
to your respective value try it it will help you
精彩评论