Community
Participate
Working Groups
If advanced graphics (GC.setAdvanced(true)) is enabled on a graphics context then calling GC.drawImage(Image image, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight) where the destination width and/or height is greater than that of the source image will draw an image with an alpha gradient. Specially, the drawn image will be the desired color at its center but have an alpha graient applied towards its edges (as if the act of stretching implies an alpha shift). An example can be quickly cooked up using SWT image snippet #112: public static void main (String [] args) { Display display = new Display (); final Image image = new Image(display, 2, 10); final Color color = display.getSystemColor(SWT.COLOR_BLUE); final GC gc = new GC (image); gc.setBackground(color); gc.fillRectangle(image.getBounds()); gc.dispose (); color.dispose (); Shell shell = new Shell (display); shell.setLayout (new FillLayout ()); Group group = new Group (shell, SWT.NONE); group.setLayout (new FillLayout ()); group.setText ("a square"); Canvas canvas = new Canvas (group, SWT.NONE); canvas.addPaintListener (new PaintListener () { public void paintControl (PaintEvent e) { // NOTE: turning on advanced graphics here (regardless of any // alpha value set) will cause the stretched image to have // an alpha gradient applied // NOTE: this same effect can be seen by performing any function // that would enabled advanced graphics such as: // e.gc.setAlpha(0xFE); // or: // e.gc.setAntialias(SWT.ON); e.gc.setAdvanced(true); // NOTE: the image is stretched in both dimensions e.gc.drawImage(image, 0, 0, 2, 10, 0, 0, 300, 300); } }); shell.pack (); shell.open (); while (!shell.isDisposed ()) { if (!display.readAndDispatch ()) display.sleep (); } image.dispose (); display.dispose (); } This gradient occurs regardless of the source of the source image (e.g. a loaded image or a created image as in the snippet above). (This bug becomes more severe with the use of GEF as there is no way to disable the use of advanced graphics on a Graphics object after it has been enabled. (And it hasn't been shown that disabling advanced graphics will even solve the problem.))
Fixed > 20050711.
(In reply to comment #0) > (This bug becomes more severe with the use of GEF as there is no way to disable > the use of advanced graphics on a Graphics object after it has been enabled. You can use push, pop, and restoreState() on Graphics to get back to a non- advanced mode.
For the default GraphicsSource (BufferedGraphicsSource) this is true. I guess I should have said that there is no *explicit* way to disable the use of advanced graphics (which there really shouldn't be). Unfortunately I am using a custom GraphicsSource that was on a GC with advanced graphics enabled. Thanks for the tip though. I may be moving back to the default GraphicsSource now that most of these bugs are ironed out. Thanks for the bug fix Silenio Quarti.
This bug seems to have sort of come back. The differences are that the artifact on the edges of the image are now always only 1 pixel wide and happen on the opposite sides of the image: the top and left as opposed to the bottom and right. I don't know if you can see the problem with the snippet referenced in this bug, but you can see it with the attachment I made to Bug 103973.
Just a note on that attachment I just referenced...the colorize method should be changed as follows to work around Bug 103691: private static void colorize(ImageData data) { int blue = data.palette.getPixel(new RGB(0, 0, 255)); for (int y=0;y < data.height;y++) for (int x=0;x < data.width;x++) { int pixel = data.getPixel(x, y); int alpha = data.getAlpha(x, y); if (pixel == data.transparentPixel || alpha == 0) { data.setPixel(x, y, blue); continue; } } }