moving an image accross a transparent background

How do I move an image across a transparent background ?

// create a transparent background

BufferedImage drawCanvas = gc.createCompatibleImage(screenW,screenH,
Transparency.TRANSLUCENT);
.
.
.

//loop

// draw an Image on the background

g.drawImage(image, x,y,w,h);

// save previous position of the image
x0=x;
y0=y;

//clip off the background
clipImage=drawCanvas.getSubimage(x0,y0,w,h);

//redraw the part of the background where image was
//This does not work before the transparency of clipImage
.
.
g.drawImage(clipImage x0,y0,w,h);

//end loop

Thanks

Jay

you say your background is transparent, what’s behind it?

if the background never actually changes (perhaps aside from scrolling or something) it might be better to paint it to a non transparent image and use that for the background, update it only whenever you have to. this way you wouldnt be repainting sections of a translucent image.

if there’s something behind the background that moves however, or it’s an animated background, then you can’t expect much performance

The background color for the component is white. Yes, I need to have the transparent background. I can somehow get around the issue by creating another non transparent image with white color :

// create a transparent background

BufferedImage drawCanvas = gc.createCompatibleImage(screenW,screenH,
Transparency.TRANSLUCENT);

BufferedImage whiteImage = gc.createCompatibleImage(screenW,screenH, Transparency.OPAQUE);
whiteImage_g2=whiteImage.createGraphics();
// set the image color white
fillWhite(whiteImage_g2,0,0,screenW,screenH);

.
.

//loop

// draw an Image on the background

g.drawImage(image, x,y,w,h);

// save previous position of the image
x0=x;
y0=y;

//clip off the white color image
clipImage=whiteImage.getSubimage(x0,y0,w,h);
// clear the background
g.drawImage(clipIamge,x0,y0,w,h);

//clip off the transparent background with whatever being drawn onto it
clipImage=drawCanvas.getSubimage(x0,y0,w,h);

//redraw the part of the background where image was
g.drawImage(clipImage, x0,y0,w,h);

//end loop

This works fine except that I have to create a non transparent buffered image with white color and waste some memory. I thought that I could just clip off the transparent background and fill it with white color. But it does not seem to work with transparent image. When I tried with the transparent image, the foreground image appears with a gray color clipped region when the foreground image is being dragged across the screen.

Thanks

Jay

just curious. do you mean transparent or translucent?

is it like a gif file with some parts you can see thru and all the rest opaque or is there semi-transparency in it as well?

i use transparent gifs all the time and they work just as fast as anything else, but if you try using png alpha trnaspatent images it kills your performance.

Alpha blending is not hardware accelerated yet, bitmasks are.

There is a property you can set for 1.4.2 beta that will enable some hardware acceleration for alpha transparency. trembovetski mentioned it in an earlier thread…

[quote]Alpha blending is not hardware accelerated yet, bitmasks are.

There is a property you can set for 1.4.2 beta that will enable some hardware acceleration for alpha transparency. trembovetski mentioned it in an earlier thread…
[/quote]
1.4.1_02 has the flags for accelerated alpha as well.