首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Print UIWebView屏幕

Print UIWebView屏幕
EN

Stack Overflow用户
提问于 2011-06-11 08:27:49
回答 3查看 1.7K关注 0票数 1

我有一个由Google Charts生成的图形的UIWebView (渲染的javascript)

屏幕不是pdf或png格式。

有没有可能捕获屏幕上的内容并将其发送到AirPrint?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-06-11 09:22:47

截取网页视图的屏幕截图,并将其发送到AirPrint。

代码语言:javascript
复制
// TAKE SCREENSHOT
CGRect myRect = [self.view bounds];
UIGraphicsBeginImageContext(myRect.size);   
CGContextRef ctx = UIGraphicsGetCurrentContext();
[[UIColor blackColor] set];
CGContextFillRect(ctx, myRect);
[self.view.layer renderInContext:ctx];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
NSData *imageData = UIImageJPEGRepresentation(viewImage, 1.0);
UIGraphicsEndImageContext();
票数 5
EN

Stack Overflow用户

发布于 2011-06-12 11:18:05

下面是翻译成Monotouch .NET c#的答案

代码语言:javascript
复制
  public static UIImage TakeScreenShot (UIView view)
{
    try
    {
        RectangleF canvasRect = view.Bounds;
        UIGraphics.BeginImageContext (canvasRect.Size);

        CGContext ctx = UIGraphics.GetCurrentContext ();
        ctx.FillRect (canvasRect);
        view.Layer.RenderInContext (ctx);

        UIImage newImage = UIGraphics.GetImageFromCurrentImageContext ();

        UIGraphics.EndImageContext ();

        return newImage;
    }
    catch
    {
        return null;
    }
}
票数 3
EN

Stack Overflow用户

发布于 2013-11-18 16:55:30

应在UIWebView.LoadFinished之后调用函数“UIGetWebViewPrintScreen”

代码语言:javascript
复制
void main()
{
  RectangleF rect(0, 0, 100, 100);
  UIWebView = new UIWebView();
  UIImage Img = null;
  string sHtml = "test string";
  WebView.LoadHtmlString(sHtml, null);
  WebView.Frame = rect;
  WebView.LoadFinished += delegate
  {
    if (UIGetWebViewPrintScreen (WebVIew, Img))
    {
      //doing with Img what you want.
    }
  }
}


public bool UIGetWebViewPrintScreen(UIWebView WebView, out UIImage Img)
    {
      bool bSuccess = false;
      //Should be call after event uiWebView.LoadFinished
      UIGraphics.BeginImageContext(WebView.ScrollView.Bounds.Size);
      CGContext cnt = UIGraphics.GetCurrentContext();
      if (cnt != null)
      {
        WebView.Layer.RenderInContext(cnt);
        Img = UIGraphics.GetImageFromCurrentImageContext();
        bSuccess = true;
      }
      else
        Img = null;
      UIGraphics.EndImageContext();

      return bSuccess;
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6313256

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档