Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] Transparency and Buffered Images

Started by DiscoTurkey Jul 29, 2002 at 3:06 AM 1 replies 350+ views
Original Post
DiscoTurkey
DiscoTurkey
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*
HenryApe
HenryApe
Maybe changing the line

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

to

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

will do the trick.
snowmoon
snowmoon
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.