Hello,
I am trying to use .java.awt.* classes in a headless (server)
environment to draw an image with a transparent background.
Example: web page with yellow background contains an image with a
black line on it. I don't want the image to contain a white rectangle
around the black line. The black line has to sit on the yellow
_web_page_ background.
The code snippet below works fine, but creates an image with a white
background.
BufferedImage image = new BufferedImage(IMAGE_CANVAS_WIDTH,
IMAGE_CANVAS_HEIGHT,
BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = image.createGraphics();
// fill background
g2d.setColor(Color.white);
g2d.fillRect(0, 0, IMAGE_CANVAS_WIDTH, IMAGE_CANVAS_HEIGHT);
I tried setting the Color to new Color(255, 255, 255, 255) and also
0,0,0,0, and neither worked. I can set the background to various
combinations of RGB, but I can't get the background to become
transparent.
Is there a way to do this in a non-Swing environment?
Any help would be appreciated.
Thanks!
ak - 23 Jan 2004 19:10 GMT
> BufferedImage image = new BufferedImage(IMAGE_CANVAS_WIDTH,
> IMAGE_CANVAS_HEIGHT,
> BufferedImage.TYPE_INT_RGB);
wrong image type - BufferedImage.TYPE_INT_RGB has no alpha!
you need BufferedImage.TYPE_INT_ARGB
____________
http://reader.imagero.com the best java image reader.