拍摄UIWebView的快照/截图

时间:2010-08-11 12:14:34

标签: ios uiwebview

如何拍摄UIWebView控件的快照/屏幕截图?

3 个答案:

答案 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);

各自的价值 尝试它会帮助你