2009-08-12 150 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

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

相關問題