Menu

#77 Black rectangle when capturing screen in JWebBrowser

v1.0_(example)
open
None
1
2020-05-11
2019-07-31
Catobus
No

Hi,

I am using a JWebBrowser in a Swing application on Windows 10 x64 bit version 1809 machine. I get a black rectangle when making a screen capture in JWebBrowser. I tried several latest versions of DJNativeSwing, including the latest '1.0.3 preview'. The print screen feature used to work on this same machine before. Also, there is another Windows 10 machine where this feature still works without problems, and some other machines where it does not.

To reproduce the problem I execute DemoExampleDefinitionLoader demo available at
/DJNativeSwing-SWTDemo/src/chrriis/dj/nativeswing/swtimpl/demo/examples/webbrowser/FullPageCaptureExample.java

As a result I get a black rectangle (see attached).

I also tried this sample - https://bugs.eclipse.org/bugs/attachment.cgi?id=93220
The result is similar - two black rectangles.

What do you think can be a problem ?

Thank you very much for your time!
C

1 Attachments

Discussion

  • Catobus

    Catobus - 2019-07-31

    I forgot to mention that I tested it with SWT versions 4.5 and 4.12. Both versions behave the same.

     
  • Christopher Deckers

    Hi,

    I am not sure what the reason could be. Maybe the graphics driver is important and in your case got updated. Or maybe the web browser got updated and the SWT printing feature does not work with that version. You could try to alter your graphics driver and see if that makes a difference...

    In any case, I am not sure how I could help you further as it seems the problem is in SWT itself...

    Hope this helps,
    -Christopher

     
  • Catobus

    Catobus - 2019-08-05

    Thank you for your help! I will try to update the drivers. By the way I also noticed the same issue on bootcamp Windows 10 on MacBook Pro 2017.

     
  • Catobus

    Catobus - 2019-09-16

    I created an SWT sample that captures an image from SWT Browser using 'browser.print()' method. It works fine. I guess it means there is no issue with SWT. Here is the sample:

    import org.eclipse.swt.SWT;
    import org.eclipse.swt.browser.Browser;
    import org.eclipse.swt.events.SelectionAdapter;
    import org.eclipse.swt.events.SelectionEvent;
    import org.eclipse.swt.graphics.GC;
    import org.eclipse.swt.graphics.Image;
    import org.eclipse.swt.layout.GridData;
    import org.eclipse.swt.layout.GridLayout;
    import org.eclipse.swt.widgets.Button;
    import org.eclipse.swt.widgets.Display;
    import org.eclipse.swt.widgets.Event;
    import org.eclipse.swt.widgets.Label;
    import org.eclipse.swt.widgets.Listener;
    import org.eclipse.swt.widgets.Shell;
    
    public class TestSWTBrowser {
        public static void main(String[] args) {
            final Display display = new Display();
            final Shell shell = new Shell(display);
            shell.setText("Browser Test");
            shell.setSize(500, 500);
            shell.setLayout(new GridLayout());
    
            final Browser browser = new Browser(shell, SWT.NONE);
            browser.setUrl("http://www.google.com");
            browser.setLayoutData(new GridData(GridData.FILL_BOTH));
    
            Button b = new Button(shell, SWT.NONE);
            b.setText("Capture");
            b.addListener(SWT.Selection, new Listener() {
                @Override
                public void handleEvent(Event event) {
                    Image img = new Image(display, browser.getSize().x, browser.getSize().y);
                    GC gc = new GC(img);
                    browser.print(gc);
                    gc.dispose();
    
                    showImage(Display.getDefault().getActiveShell(), img);
                }
            });
    
            shell.open();
            while (!shell.isDisposed()) {
                if (!display.readAndDispatch())
                    display.sleep();
            }
            display.dispose();
        }
    
        public static void showImage(Shell parentShell, Image img) {
            Shell shell = new Shell(parentShell);
    
            shell.setLayout(new GridLayout());
    
            Label label = new Label(shell, SWT.NONE);
            label.setImage(img);
    
            Button ok = new Button(shell, SWT.PUSH);
            ok.setText("OK");
            ok.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
            ok.addSelectionListener(new SelectionAdapter() {
                public void widgetSelected(SelectionEvent event) {
                    shell.close();
                }
            });
            shell.setDefaultButton(ok);     
            shell.pack();
            shell.open();
    
            Display display = parentShell.getDisplay();
            while (!shell.isDisposed()) {
                if (!display.readAndDispatch()) {
                    display.sleep();
                }
            }
        }
    }
    
     
  • Rodrigo Fortes

    Rodrigo Fortes - 2020-05-11

    I also have the same problem, I think something in control.print (gc), but I can't find any correction

     

Log in to post a comment.