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;
}
[java] Java 2D query
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.
However this doesn't display my PNG file with the surrounding transparency. All I get is a black rectangle. Help!
Many Thanks
Anthony
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.
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.
Try this:
Tested and got this working for me.
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f));
Tested and got this working for me.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement