Jump to content
  • Advertisement

Archived

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

DiscoTurkey

[java] Transparency and Buffered Images

This topic is 5924 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!