Cómo capturar una página del navegador representación del lado del cliente?

StackOverflow https://stackoverflow.com/questions/1266568

  •  13-09-2019
  •  | 
  •  

Pregunta

No estoy seguro si esto es posible, pero me gustaría agregar un control / objeto a una página web para que los usuarios finales pueden hacer clic en un botón para capturar lo que están viendo en el navegador para que luego puedan presentar la imagen de nuevo como parte de un proceso de revisión sitio web.

Yo había pensado control ActiveX, pero si podíamos usar flash o Silverlight que sería mejor.

Gracias por cualquier sugerencia.

¿Fue útil?

Solución

En Windows, puede pulsar Alt + PrintScreen para copiar la ventana actual en el portapapeles.

Si puede utilizar FireFox, sugiero mirar libro de recuerdos + .

Si necesita un proceso automatizado, prueba a SWT . Esta biblioteca tiene un componente de navegador que se puede utilizar para cargar algo de HTML, mostrar y copiar el resultado en una imagen. El problema es saber cuando el navegador ha terminado la representación del documento. Este fragmento de código debería empezar:

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

Otros consejos

El botón de impresión de pantalla? Cualquier otra cosa sería muy difícil de hacer correctamente.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top