I want to draw single character with specified Font and transparent background to an SWT Image, later save it to file. I do it like this:
FontData fontData; // info about the font
char ch = 'a'; // character to draw
Display display = Display.getDefault();
TextLayout textLayout = new TextLayout(display);
textLayout.setAlignment(SWT.CENTER);
textLayout.setFont(font);
textLayout.setText("" + ch);
Rectangle r = textLayout.getBounds();
Image img = new Image(display, r.width, r.height);
GC gc = new GC(img);
textLayout.draw(gc, 0, 0);
The character is drawn but it gets white background. I tried to solve it by setting transparentPixel to white color, this makes background transparent but character looks ugly. I also tried to set alphaData of the Image with 0's (fully transparent) before drawing anything on it, but alphaData doesn't update after drawing anything on the Image, it stays transparent all the time. How to draw character with transparent background on the Image?