<bdo id='7E84S'></bdo><ul id='7E84S'></ul>

    1. <tfoot id='7E84S'></tfoot>

      <small id='7E84S'></small><noframes id='7E84S'>

      <legend id='7E84S'><style id='7E84S'><dir id='7E84S'><q id='7E84S'></q></dir></style></legend>

    2. <i id='7E84S'><tr id='7E84S'><dt id='7E84S'><q id='7E84S'><span id='7E84S'><b id='7E84S'><form id='7E84S'><ins id='7E84S'></ins><ul id='7E84S'></ul><sub id='7E84S'></sub></form><legend id='7E84S'></legend><bdo id='7E84S'><pre id='7E84S'><center id='7E84S'></center></pre></bdo></b><th id='7E84S'></th></span></q></dt></tr></i><div id='7E84S'><tfoot id='7E84S'></tfoot><dl id='7E84S'><fieldset id='7E84S'></fieldset></dl></div>
    3. 如何从 UIWebView 获取整个图像,包括屏幕外内容

      时间:2023-11-09

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

          <tbody id='jbDap'></tbody>

          <bdo id='jbDap'></bdo><ul id='jbDap'></ul>
            • <small id='jbDap'></small><noframes id='jbDap'>

                <legend id='jbDap'><style id='jbDap'><dir id='jbDap'><q id='jbDap'></q></dir></style></legend>
              1. 本文介绍了如何从 UIWebView 获取整个图像,包括屏幕外内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有一种方法可以从我的 iOS 应用程序中的各种视图中获取图像,以便让用户通过电子邮件发送屏幕.我绘制的大多数屏幕都可以正常工作,但是当我将这种技术与 UIWebView 一起使用时,我只能得到屏幕的可见部分.屏幕外的任何内容都不包含在渲染图像中.一直在 Stack 上挖掘,但到目前为止我还没有找到工作?!

                I have a method I use to get images from a various views in my iOS application for letting users email screens. Most of the screens where I draw are working ok, but when I use this technique with a UIWebView I only get the visible portion of the Screen. Anything off screen is not included in the rendered image. Been digging around here on Stack, but so far nothing I have found works?!

                这是我目前使用的方法:

                Here is the method I currently use:

                -(NSData *)getImageFromView:(UIView *)view
                {
                    NSData *pngImg;
                    CGFloat max, scale = 1.0;
                    CGSize size = [view bounds].size;
                
                    // Scale down larger images else we run into mem issues with mail widget
                    max = (size.width > size.height) ? size.width : size.height;
                    if( max > 960 )
                        scale = 960/max;
                
                    UIGraphicsBeginImageContextWithOptions( size, YES, scale );
                
                    CGContextRef context = UIGraphicsGetCurrentContext();
                    [view.layer renderInContext:context];    
                    pngImg = UIImagePNGRepresentation( UIGraphicsGetImageFromCurrentImageContext() );
                
                    UIGraphicsEndImageContext();    
                    return pngImg;
                }
                

                推荐答案

                哇,答案简直太简单了……正在到处寻找各种与打印/PDF相关的东西……然后我突然想到,为什么不只是将上下文中的视图设置为 sizeThatFits.成功了!

                Wow the answer was stupidly simple... was digging all over the place looking at various Printing/PDF related stuff... then it occurred to me, why not just set the view IN THE CONTEXT to a sizeThatFits. It worked!

                警告:不能保证您不会遇到内存问题,我建议您在 @autoreleasepool 池中执行此操作,并考虑像我在示例中所做的那样进行一些缩放,但这有效并且是我决定的:

                WARNING: No guarantee you don't run into mem issues with this and I DO suggest you do this inside an @autoreleasepool pool and consider doing some scaling as I do in the example, but THIS WORKS and is what I settled on:

                -(NSData *)getImageFromView:(UIView *)view  // Mine is UIWebView but should work for any
                {
                    NSData *pngImg;
                    CGFloat max, scale = 1.0;
                    CGSize viewSize = [view bounds].size;
                
                    // Get the size of the the FULL Content, not just the bit that is visible
                    CGSize size = [view sizeThatFits:CGSizeZero];
                
                    // Scale down if on iPad to something more reasonable
                    max = (viewSize.width > viewSize.height) ? viewSize.width : viewSize.height;
                    if( max > 960 )
                        scale = 960/max;
                
                    UIGraphicsBeginImageContextWithOptions( size, YES, scale );
                
                    // Set the view to the FULL size of the content.
                    [view setFrame: CGRectMake(0, 0, size.width, size.height)];
                
                    CGContextRef context = UIGraphicsGetCurrentContext();
                    [view.layer renderInContext:context];    
                    pngImg = UIImagePNGRepresentation( UIGraphicsGetImageFromCurrentImageContext() );
                
                    UIGraphicsEndImageContext();
                    return pngImg;    // Voila an image of the ENTIRE CONTENT, not just visible bit
                }
                

                这篇关于如何从 UIWebView 获取整个图像,包括屏幕外内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:UIWebView 和 NSURLCache 关系有问题 下一篇:如果使用 loadHTMLString 加载视图,如何在 uiwebview 中设置 http 标头

                相关文章

                  1. <legend id='XZ4vJ'><style id='XZ4vJ'><dir id='XZ4vJ'><q id='XZ4vJ'></q></dir></style></legend>

                    <tfoot id='XZ4vJ'></tfoot>
                  2. <small id='XZ4vJ'></small><noframes id='XZ4vJ'>

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