[java] alpha blending in java?
Members - Reputation: 122
Posted 06 February 2008 - 02:01 PM
Graphics2D g2d = (Graphics2D)g;
Composite composite = g2d.getComposite();
// 0.5f is alpha
AlphaComposite alphaComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f);
Also, I'm not sure about this, but either the regular graphics class or only the graphics2d class will obay image transparencies. For example, if I set a certain color in my image as transparent, using g2d.drawImage() will blit the image while keeping the transparency.
Members - Reputation: 100
Posted 06 February 2008 - 02:29 PM
Graphics2D g2d = (Graphics2D)g
I'm going to assume that this is a typecast (I haven't seen too much typecasting in Java, but I've been using 1.1-ish code so I'm guessing this is more common in 1.2). Just not sure why it is necessary. Why not replace paint() entirely?
Also... it seems that this will make the object have an "alpha" value. What I am looking to do is to make a portion of an image file (i.e. bitmap, gif, png) - say the white background - transparent, while the rest of the image still renders. This is a common technique very easy to achieve with OpenGL or DirectX. I need to target a *specific* RGB value and tell my program to ignore it in paint.
Members - Reputation: 523
Posted 06 February 2008 - 03:11 PM
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][LWJGL Tutorials for NeHe][LWJGL Wiki][jMonkey Engine]
Members - Reputation: 236
Posted 12 February 2008 - 10:25 AM
have to roll your own. You could use GIF or PNG format, but GIF isn't
full color, and PNG has crummy compression and spotty support. My solution
is to use pairs of jpeg images and composite them as part of the image
---visit my game site http://www.boardspace.net - free online strategy games
Members - Reputation: 112
Posted 22 February 2008 - 07:49 AM
You can draw the java.awt.Image onto a BufferedImage. Then you can call
yourBImg.createGraphics(). Now you will be able to use all the new Graphics2D functionalities.
Hope this will help!