<legend id='RE9Kf'><style id='RE9Kf'><dir id='RE9Kf'><q id='RE9Kf'></q></dir></style></legend>

    <small id='RE9Kf'></small><noframes id='RE9Kf'>

    <i id='RE9Kf'><tr id='RE9Kf'><dt id='RE9Kf'><q id='RE9Kf'><span id='RE9Kf'><b id='RE9Kf'><form id='RE9Kf'><ins id='RE9Kf'></ins><ul id='RE9Kf'></ul><sub id='RE9Kf'></sub></form><legend id='RE9Kf'></legend><bdo id='RE9Kf'><pre id='RE9Kf'><center id='RE9Kf'></center></pre></bdo></b><th id='RE9Kf'></th></span></q></dt></tr></i><div id='RE9Kf'><tfoot id='RE9Kf'></tfoot><dl id='RE9Kf'><fieldset id='RE9Kf'></fieldset></dl></div>
      <bdo id='RE9Kf'></bdo><ul id='RE9Kf'></ul>
    <tfoot id='RE9Kf'></tfoot>

        将 UIWebView 渲染到 ImageContext

        Rendering a UIWebView into an ImageContext(将 UIWebView 渲染到 ImageContext)
              <bdo id='qP6XA'></bdo><ul id='qP6XA'></ul>
                <tbody id='qP6XA'></tbody>
            • <small id='qP6XA'></small><noframes id='qP6XA'>

              1. <tfoot id='qP6XA'></tfoot>

                <i id='qP6XA'><tr id='qP6XA'><dt id='qP6XA'><q id='qP6XA'><span id='qP6XA'><b id='qP6XA'><form id='qP6XA'><ins id='qP6XA'></ins><ul id='qP6XA'></ul><sub id='qP6XA'></sub></form><legend id='qP6XA'></legend><bdo id='qP6XA'><pre id='qP6XA'><center id='qP6XA'></center></pre></bdo></b><th id='qP6XA'></th></span></q></dt></tr></i><div id='qP6XA'><tfoot id='qP6XA'></tfoot><dl id='qP6XA'><fieldset id='qP6XA'></fieldset></dl></div>
                <legend id='qP6XA'><style id='qP6XA'><dir id='qP6XA'><q id='qP6XA'></q></dir></style></legend>

                  本文介绍了将 UIWebView 渲染到 ImageContext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试捕获 UIWebView 的内容,包括对用户不可见的内容.即整个网页,即使用户只看顶部.

                  I am trying to capture the contents of a UIWebView including that which is not visible to the user. i.e. The whole web page even though the user is only looking at the top.

                  环顾四周,我发现捕获 UIView 的最佳方法是检索其层并使用 renderInContext.

                  Looking around I found the best way to capture a UIView is to retrieve its layer and use renderInContext.

                  然而,UIWebView 似乎在使用它自己的 CALayer 实现,它的行为更像 CATiledLayer,尽管它仍然声称是标准的 CALayer.当我调用 renderInContext 时,我只得到网页的一部分,最多向下 940 像素,而不是整个页面.

                  However, UIWebView seems to be using its own CALayer implementation which is behaving a lot more like CATiledLayer, although it is still claiming to be a standard CALayer. When I call renderInContext I only get one portion of the web page, up to 940px down, as opposed to the whole page.

                  有没有人有任何想法:强制 UIWebView 向下滚动另一个 940 像素(显然这远非理想),或者当我问它时告诉它支持 WebView 的任何种类的 CALayer 来呈现其所有内容到.

                  Has anyone got any ideas on how to either: force the UIWebView to scroll down another 940px (obviously that is far from ideal) or tell whatever breed of CALayer it is backing the WebView to render all of its content when I ask it to.

                  干杯

                  我应该添加当前更改 webview 的框架以适合通过 javascript 检索的页面的大小.

                  I should add that currently change the frame of the webview to fit the size of the page retrieved through javascript.

                  推荐答案

                  我发布了一个应用程序(Web2Pic) 这样做,请相信我 UIGraphicsBeginImageContext(webView.frame.size);除了从我们的 UIWebView 中的可见区域获取一个小图像之外,什么也做不了;-(

                  I've released an app (Web2Pic) doing that, and please trust me that UIGraphicsBeginImageContext(webView.frame.size); can do nothing except getting a small image from the visible area in our UIWebView ;-(

                  正确的方法有点复杂,但它确实有效:

                  The right way is a bit complex but it just works:

                  1.在我们的 UIWebView 中使用 JavaScript 来获取这些浮点值:

                  1.Use JavaScript in our UIWebView to get these float values:

                     //Whole page size in HTML coordinate
                     document.body.scrollWidth
                     document.body.scrollHeight
                     //UIWebView visible size in HTML coordinate
                     window.innerWidth
                     window.innerHeight
                  

                  2.现在我们可以将整个页面切割"成几十个 UIWebView 大小的小块.然后我们可以单独捕获每个小块并将它们保存到我们的缓存中.我通过计算页面偏移来实现这一点,并使用 UIGraphicsBeginImageContext(webView.frame.size); 来获取图像数组.另外,你应该将图像数组缓存到文件系统中,否则应用程序最终会崩溃!

                  2.Now we can 'cut' the whole page into dozens of UIWebView-sized small pieces. Then we can capture every small pieces individually and save them into our Cache. I implemented this by calculating page-offsets and use UIGraphicsBeginImageContext(webView.frame.size); to get a array of images. In addition, you should cache the image array into the file system, or the app will eventually crash!

                  3.当我们最终得到所有小块时,我们可以启动一个全分辨率上下文:UIGraphicsBeginImageContext(CGSizeMake(document.body.scrollWidth,document.body.scrollHeight));

                  3.When we finally got all the small pieces, we can start a full-resolution context: UIGraphicsBeginImageContext(CGSizeMake(document.body.scrollWidth,document.body.scrollHeight));

                  4.根据坐标将每个小图像渲染到大上下文中.并且小心角落,每行/行中的最后一张图片可能不是完整的图片.

                  4.Render every small images into the big context based on the coordinates. And be careful to the corners, the last image in every line/row may not be a full image.

                  5.还有一步:保存大图.请勿将其保存到相册中,因为 iOS 会自动降低相册中图片的分辨率.相反,我们可以将其保存到文件系统中并启用应用的 iTunes 文件共享 支持,甚至可以编写一个简单的应用内照片管理器.

                  5.There is still one step left: saving the big image. Do not save it into the PhotoAlbum, because iOS will automatically cut down the resolution of images in the album. Instead, we can save it into the file system and enable the app's iTunes File Share support, or even write a simple in-app photo manager.

                  希望这些可以帮助;-)

                  Hope these can help ;-)

                  一朝峰姬

                  这篇关于将 UIWebView 渲染到 ImageContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Getting an NSArray of a single attribute from an NSArray(从 NSArray 获取单个属性的 NSArray)
                  ImageIO: lt;ERRORgt; JPEG Corrupt JPEG data: premature end of data segment iphone - how to catch this?(ImageIO:lt;错误gt;JPEG 损坏的 JPEG 数据:iphone 数据段过早结束 - 如何捕捉到这个?)
                  How to get indexPath.row of tableView which is currently being displayed?(如何获取当前正在显示的 tableView 的 indexPath.row?)
                  Xcode iOS organizer submit to app store yields quot;The archive is invalidquot; error(Xcode iOS 管理器提交到应用商店产生“存档无效;错误)
                  MFMessageComposeViewController alloc returns nil(MFMessageComposeViewController alloc 返回 nil)
                  Mobile Device Management with iPhone(使用 iPhone 进行移动设备管理)
                  <i id='EOU4u'><tr id='EOU4u'><dt id='EOU4u'><q id='EOU4u'><span id='EOU4u'><b id='EOU4u'><form id='EOU4u'><ins id='EOU4u'></ins><ul id='EOU4u'></ul><sub id='EOU4u'></sub></form><legend id='EOU4u'></legend><bdo id='EOU4u'><pre id='EOU4u'><center id='EOU4u'></center></pre></bdo></b><th id='EOU4u'></th></span></q></dt></tr></i><div id='EOU4u'><tfoot id='EOU4u'></tfoot><dl id='EOU4u'><fieldset id='EOU4u'></fieldset></dl></div>
                    <bdo id='EOU4u'></bdo><ul id='EOU4u'></ul>

                      <tbody id='EOU4u'></tbody>

                    <tfoot id='EOU4u'></tfoot>
                    <legend id='EOU4u'><style id='EOU4u'><dir id='EOU4u'><q id='EOU4u'></q></dir></style></legend>

                          1. <small id='EOU4u'></small><noframes id='EOU4u'>