Archived

This topic is now archived and is closed to further replies.

DiscoTurkey

[java] Transparency and Buffered Images

Recommended Posts

Hello all, I''m writing a puzzle game that involves accumulating pieces onto a game board (think Tetris or Bubble Bobble). Currently, I''m using a function similar to the one below to generate the "pile" of pieces and draw it onto a bufferedImage. I then return the generated image and draw it to screen from within my paint method. //the method private Image generateLayer(int width, int height) { BufferedImage bImage; Graphics2D bg2; bImage = (BufferedImage)createImage(width, height); bg2 = bImage.createGraphics(); //generate "pile" here by drawing tiles to bImage //with calls to bg2.drawImage() return bImage; } I''ve encountered a problem with this technique: though the pile isn''t rectangular, the image returned by the function is. As a result, there''s an unsightly gray rectangle around the pile when I draw it over the background image. I would like to be able to create a transparent buffer that I can draw arbitrary shapes onto, then blit that onto the final composite image. Any suggestions on how to accomplish this, or on an alternative approach? Many thanks, *DiscoTurkey*

Share this post


Link to post
Share on other sites
Maybe changing the line

bImage = (BufferedImage)createImage(width, height);

to

bImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

will do the trick.

Share this post


Link to post
Share on other sites
For faster drawing you might want to use GraphicsConfiguration.createCompatibleImage(w,h,trans) as the bufferedimage returned is optimally orginized for your current screen depth and configuration.

Share this post


Link to post
Share on other sites