Hello, Are you trying to blend the images in a Swing window, for example? Either way, AlphaComposite is your friend. The basic approach looks like this:
float alpha = 0f; public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D)g; Composite oldcomp = g2.getComposite(); // draw first image fully opaque g2.drawImage(img1, 0, 0, null); // change opacity of second image after each call to repaint() g2.setComposite(AlphaComposite.getInstance(SRC_OVER, alpha)); g2.drawImage(img2, 0, 0, null); g2.setComposite(oldcomp); } while (!done) { alpha += 0.1; repaint(); ... } Chris On Nov 29, 2006, at 3:54 AM, [EMAIL PROTECTED] wrote:
Hi all, I've searched the web for 3 hours now, without a result. Is there a simple and PERFORMANT way to blend two images (BufferedImages) in/ over each other? I want to build up an alphablending-animation, which smoothly blends the old image out (alpha from 255 to 0) while the new is blended in (alpha from 0 to 255) ... i found several alphablending algorithms but nowhere a simple example in java. 1. my first idea is to create dynamically a kind of result image. each pixel (color) of the result image is calculated via a simple equation. the problem is: i need the color palette as byte array ... 2. another idea is to render both images separately with an AlphaComposite. then the 2 resulting images have to be merged into one result images (addition). could anybody help me with a link or an example in java? are any other solutions for this common problem? thanks a lot. K4simir [Message sent by forum member 'k4simir' (k4simir)] http://forums.java.net/jive/thread.jspa?messageID=180212 ====================================================================== ===== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JAVA2D-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".
=========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JAVA2D-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".