Eclipse / SWT:图像副本显示为空白

时间:2017-11-21 02:51:36

标签: eclipse image swt graphicscontext

我在Eclipse插件中有以下代码来截取屏幕截图并显示图像的两个副本。在将来,我将对第二个副本进行一些修改,但是现在只显示一个精确的副本就足够了。但是,第二个副本显示为空白。

screenshot.getImageData().data似乎是一个0和-1的数组:[0, -1, -1, -1, 0, -1, -1, -1, ... ]

任何想法可能导致第二张图片为空白或我应该尝试什么?

谢谢

// 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 个答案:

没有答案