Jump to content
  • Advertisement
Sign in to follow this  
MangoSupremacy

[java] Java 2D query

This topic is 4153 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

Here's a quick JAVA 2D question. I'm running Wicket and want to dynamically generate/modify images sent to the browser. Wicket supplies the following method to override.
protected boolean render(Graphics2D graphics)
			        {
                        try {
                            BufferedImage image = ImageIO.read(new File("C:\\Projets\\randoweb\\src\\com\\tentelemed\\randoweb\\ui\\rando.png"));

                            BufferedImage bi= new BufferedImage(32, 32, BufferedImage.TYPE_INT_ARGB);
                            Graphics2D g2 = bi.createGraphics();
                            g2.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
                                        RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
                            g2.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR, 0.0f));
                            Rectangle2D.Double rect = new Rectangle2D.Double(0,0,32,32);
                            g2.fill(rect);
                            //g2.drawImage(image,0,0,null);


                            graphics.drawImage(bi, 0, 0, null);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
				        return true;
                    }
However this doesn't display my PNG file with the surrounding transparency. All I get is a black rectangle. Help! Many Thanks Anthony

Share this post


Link to post
Share on other sites
Advertisement
Well normally I shouldn't see anything with that code as bi is cleared via g2 however I get a black square... I tried the same thing clearing graphics as well but to no avail.

Share this post


Link to post
Share on other sites

What happens when you change the code to this?
(haven't pasted the complete method)


g2.setComposite(AlphaComposite.getInstance(AlphaComposite.DST_OVER, 1.0f));
Rectangle2D.Double rect = new Rectangle2D.Double(0,0,32,32);
g2.fill(rect);
g2.drawImage(image,0,0,null);






As far as I know AlphaComposite.CLEAR draws nothing on the combined image.

Share this post


Link to post
Share on other sites
Try this:


g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f));



Tested and got this working for me.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!