2009-08-12 152 views
1

不知道这是否甚至可能,但我想添加一个控件/对象到网页,以便最终用户可以点击一个按钮来捕获他们在浏览器中看到的内容,然后他们可以提交图像作为一部分的网站审查过程。如何从客户端捕获浏览器页面呈现?

我曾经想过ActiveX控件,但如果我们可以使用闪光灯或银光会更好。

感谢您的任何建议。

回答

1

在Windows上,您可以按Alt + PrintScreen将当前窗口复制到剪贴板。

如果你可以使用FireFox,我建议看看ScrapBook+

如果您需要自动过程,请尝试SWT。这个库有一个浏览器组件,您可以使用它来加载一些HTML,显示它并将结果复制到图像中。问题是要知道浏览器何时完成了文档的渲染。这段代码片段应该让你开始:

public HTML2Png() 
{ 
    display = new Display(); 
    shell = new Shell(display); 
    shell.setLayout(new FillLayout()); 
    shell.setSize(920, 700); 
    shell.setLocation(10, 20); 
    browser = new Browser(shell, SWT.NONE); 

    browser.addProgressListener(new ProgressListener() { 
     public void changed (ProgressEvent progressevent) 
     { 
     } 

     public void completed (ProgressEvent progressevent) 
     { 
      boolean result = browser.execute("window.status=document.bgColor;"); 
      if (!result) 
      { 
       System.err.println("Executing script failed!"); 
       return; 
      } 

      System.out.println("Loading completed."); 
      completed.set(true); 
     } 
    }); 
    browser.addPaintListener(new PaintListener() { 
     public void paintControl (PaintEvent paintevent) 
     { 
      System.out.println(paintevent); 
     } 
    }); 
} 

void createPNG (String url, String pngFile) 
{ 
    System.out.println("Working on "+url); 
    completed.set(false); 

    shell.open(); 

    browser.setText("<html><body bgcolor=\"#FF00FF\"></body></html>"); 
    GC source = new GC (shell); 
    int testColor = 0xFF00FF00; 
    Image image = new Image (display, new Rectangle(0, 0, 1, 1)); 

    int i = 100; 
    while (display.readAndDispatch() && i > 0) 
    { 
     source.copyArea(image, 0, 0); 
     if (image.getImageData().getPixel(0,0) == testColor) 
      break; 
     sleep(); 
     i --; 
    } 

    if (i == 0) 
     throw new RuntimeException("Loading took too long"); 

    completed.set(false); 
    browser.setUrl(url); 
    i = 50; 
    while (!shell.isDisposed() && i > 0) 
    { 
     if (completed.get()) 
     { 
      source.copyArea(image, 0, 0); 
      if (image.getImageData().getPixel(0,0) != testColor) 
      { 
       image = new Image (display, browser.getClientArea()); 
       source.copyArea(image, 0, 0); 

       //if (checkImage(image, testColor)) 
        break; 
      } 

      i --; 
     } 

     while (display.readAndDispatch()) 
      ; 

     sleep(); 
    } 

    if (i == 0) 
     throw new RuntimeException ("Loading timed out"); 

    ImageLoader io = new ImageLoader(); 
    io.data = new ImageData[] { image.getImageData() }; 
    File f = new File (pngFile); 
    io.save (f.getAbsolutePath(), SWT.IMAGE_PNG); 

    System.out.println("Saved image "+f+", "+f.length()+" bytes"); 
} 
+0

这会将其保存在客户机上,但不会将其提交回服务器。 – MusiGenesis 2009-08-12 14:43:36

-1

打印屏幕按钮?其他任何事情都很难做到很好。

相关问题