[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.platform.swt] Direct text rendering to an image
|
- From: kirillcool@xxxxxxxxx (Kirill Grouchnikov)
- Date: Wed, 14 Nov 2007 05:52:50 +0000 (UTC)
- Newsgroups: eclipse.platform.swt
- Organization: Eclipse
- User-agent: NewsPortal/0.36 (http://florian-amrhein.de/newsportal)
I'm trying this code to render text to image:
Display display = Display.getDefault();
int SIZE = 400;
Image image = new Image(display, new Rectangle(0, 0, SIZE, SIZE));
GC gc = new GC(image);
gc.setTextAntialias(SWT.DEFAULT);
gc.setForeground(display.getSystemColor(SWT.COLOR_BLACK));
gc.drawText("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 10,
10, true);
and then iterate over the pixels in the image to create a Swing
BufferedImage:
ImageData imageData = image.getImageData();
BufferedImage bi = new BufferedImage(SIZE, SIZE,
BufferedImage.TYPE_INT_ARGB);
for (int i = 0; i < SIZE; i++) {
for (int j = 0; j < SIZE; j++) {
int pixel = imageData.getPixel(i, j);
int red = (pixel >>> 24) & 0xFF;
int green = (pixel >>> 16) & 0xFF;
int blue = (pixel >>> 8) & 0xFF;
int alpha = imageData.getAlpha(i, j);
bi.setRGB(i, j, alpha << 24 | red << 16 | green << 8 | blue);
}
}
If then i display this image on a Swing frame, i see that the text
rendering is much less crisp than the "pure" SWT rendering with Canvas and
paintListener that calls drawText on GC of the passed event.
Is there anything that i'm missing in the configuration of the GC or
copying the pixels from SWT Image to Swing BufferedImage?
Thanks
Kirill