Pergunta

Não tenho certeza se isso é mesmo possível, mas eu gostaria de adicionar um controle / objeto para uma página web para que usuários finais podem clicar em um botão para capturar o que eles estão vendo no navegador para que eles possam, em seguida, submeter o para trás a imagem como parte de um processo de revisão website.

Eu tinha pensado controle ActiveX, mas se pudéssemos usar flash ou silverlight que seria melhor.

Obrigado por todas as sugestões.

Foi útil?

Solução

No Windows, você pode pressionar Alt + PrintScreen para copiar a janela atual para a área de transferência.

Se você pode usar o Firefox, eu sugiro que olhar para ScrapBook + .

Se você precisar de um processo automatizado, tente SWT . Esta biblioteca tem um componente de navegador que pode ser usado para carregar alguns HTML, exibi-lo e copiar o resultado em uma imagem. O problema é saber quando o navegador tenha terminado tornando o documento. Este fragmento de código deve começar:

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");
}

Outras dicas

O botão Print Screen

? Qualquer outra coisa seria muito difícil de fazer corretamente.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top