查找将UIWebView的内容捕获到图像文件的示例,全部在后台。很可能UIWebView将被隐藏或框住主窗口,因此用户永远不会发现这种情况。
提前致谢!
罗布
答案 0 :(得分:0)
以下代码将捕获webview的内容,并将其另存为.png文件
UIGraphicsBeginImageContext(webview.bounds.size);
[webview.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// Write image to PNG
NSString *pngPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.png"];
[UIImagePNGRepresentation(image) writeToFile:pngPath atomically:YES];