【问题标题】:Save image from WebView IOS从 WebView IOS 保存图像
【发布时间】:2014-04-11 09:53:53
【问题描述】:

我目前正在将 html 文件加载到 UIWebView,有时它是表格或 png 图像,我可以保存图像和表格,但它需要在 UIWebView 中可见的图像。查看我的代码:-

 UIGraphicsBeginImageContext(theWebView.bounds.size);
   // UIGraphicsBeginImageContext(theWebView.frame.size);
    [theWebView.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);

尝试了两种方式,框架和边界。 Bounds 给了我完整的图像,但它的模糊 & 我需要设置内容以适应 UIWebView 以便我可以缩放和滚动 UIWebView。

如果我使用以下代码将UIWebView 的内容设置为中心,则由于缩放页面以适应属性,我无法滚动。

NSString *bodyStyle = @"document.getElementsByTagName('body')[0].style.textAlign = 'center';";
    [theWebView stringByEvaluatingJavaScriptFromString:bodyStyle];

我如何将页面设置为中心/适当的用户可以滚动并将整个 html 页面保存到相册中的图像。

【问题讨论】:

    标签: ios objective-c uiwebview core-graphics uigraphicscontext


    【解决方案1】:
    [theWebView sizeToFit];
    

    再次使用上述代码和调整框架UIWebView。

    【讨论】:

      猜你喜欢
      • 2017-02-26
      • 1970-01-01
      • 1970-01-01
      • 2012-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-24
      • 1970-01-01
      相关资源
      最近更新 更多