0

寻找一个将 UIWebView 的内容捕获到图像文件的示例,所有这些都在后台。UIWebView 很可能会被隐藏或框出主窗口,因此用户永远不会看到这种情况发生。

提前致谢!

4

1 回答 1

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];
于 2013-05-01T14:44:19.277 回答