I'm building a GUI with the Eclipse Window Builder Editor. I've made a Composite with a Gridlayout and have put a Label in there. Some method from another class generates a raw 8 bit 1280x1024 grayscale image which is saved in a byte array. This is how I generate my ImageData, etc in the mainMethod :
Color white = display.getSystemColor(SWT.COLOR_WHITE);
Color black = display.getSystemColor(SWT.COLOR_BLACK);
PaletteData palette = new PaletteData( 255, 255, 255 );
imgData = new ImageData(1280, 1024, 8, palette);
imgLabel = new Label(composite_3, SWT.NONE);
imgLabel.setImage(null);
imgLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
I'm still having problems to understand what exactly I should do with the PaletteData as I don't need colours anyway. (Color)Depth should be 8 because I want it to have 255 grayvalues?
And this is my setImg method which gets called from another Thread as soon as the byte[] is filled with data:
public static void setImg(final byte[] b) {
Display.getDefault().syncExec( new Runnable() {
@Override
public void run() {
imgData.setPixels(0, 0, 1280, b, 0);
img = new Image(Display.getCurrent(), imgData);
Image grayImg = new Image(Display.getCurrent(), img, SWT.IMAGE_GRAY);
imgLabel.setImage(img);
// img.dispose();
}
});
}
I've tried
imgLabel.setImage(img);
and
imgLabel.setImage(grayImg);
Ok the first line now displays correctly... It seems that I only can set 1 line of pixels with imgData.setPixels(...) which is kind of useless imo or am I doing something else wrong?