如何拍摄UIWebView
控件的快照/屏幕截图?
答案 0 :(得分:7)
接受的答案是正确的,但屏幕截图不是视网膜分辨率。
使用UIGraphicsBeginImageContextWithOptions
并将其缩放参数设置为0.0f使其以原始分辨率捕获。
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();
答案 1 :(得分:4)
使用此:
UIGraphicsBeginImageContext(rect.size);
[webView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
答案 2 :(得分:3)
使用此代码截取屏幕截图并将其保存到库中
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, self, nil, nil);
您可以通过更改
来更改屏幕截图UIGraphicsBeginImageContext(self.view.bounds.size);
各自的价值 尝试它会帮助你