我想用指定的字體和透明背景繪製單個字符到SWT圖像,稍後將其保存到文件。我不喜歡這樣寫道:字體到SWT圖像
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);
人物繪製,但它得到的白色背景。 我試圖通過將transparentPixel設置爲白色來解決它,這使得背景透明,但字符看起來很醜。 我也嘗試在繪製任何東西之前將圖像的alphaData設置爲0(完全透明),但在繪製圖像上的任何東西后alphaData不會更新,它始終保持透明。 如何在圖像上繪製具有透明背景的字符?
SWT的功能要求:https://bugs.eclipse.org/bugs/show_bug.cgi?id=508299 – 2016-11-28 20:15:25