Eclipse/SWT: Copy of image is shown as blank

220 Views Asked by At

I have the following code in an Eclipse plugin to take a screenshot and display two copies of the image. In the future, I'll be making some modification to the second copy, but for now just displaying an exact copy would be sufficient. However, the second copy displays as blank.

It appears that screenshot.getImageData().data is an array of 0s and -1s: [0, -1, -1, -1, 0, -1, -1, -1, ... ].

Any ideas what might be causing the second image to be blank or what I should try?

Thank you

// Take a screenshot
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
Shell shell = window.getShell();
Display display = shell.getDisplay();

Rectangle windowBounds = shell.getBounds();

GC gc = new GC(display);
Image screenshot = new Image(display, windowBounds);
gc.copyArea(screenshot, windowBounds.x, windowBounds.y);
gc.dispose();


// Display the images
Composite container = (Composite) super.createDialogArea(parent);
container.setLayout(new GridLayout(1, false));
container.setBackground(new Color(Display.getDefault(), 255, 255, 0));

new Label(container, SWT.NONE).setImage(screenshot);

// Copy of screenshot. To be scaled down at a later time
Image scaledSS = new Image(screenshot.getDevice(), screenshot.getImageData());

new Label(container, SWT.NONE).setImage(scaledSS);

enter image description here

0

There are 0 best solutions below