advertisement
javaboutique
Search Tips
Articles  |   Tutorials  |   Reviews  |   Tools  |   by Category  |   by Date  |   by Name  |   Submit  |   Source  |   Forums  |  
javaboutique
Browse DevX


Partners & Affiliates











advertisement


Reviews : Java Books :
Beginning Java 2- JDK 1.3 Version : Images and Animation

Buy this book
Title: Beginning Java 2- JDK 1.3 Version
ISBN: 1861003668
US Price: $ 49.99
Canadian Price:
C$ 74.95
UK Price: £ 35.99
Publication Date: March 2000
Pages: 1230
© Wrox Press Limited, US and UK.

Beginning Java 2- JDK 1.3 Version
Images and Animation

Transforming Images

Alpha compositing is all about the transparency of an image, and we are just going to look at the basic ideas here. The subject of color representation is itself a major topic with a range of different ways of representing color, but we will assume we are dealing with the RGB model throughout and ignore other color models. Note that Java does provide much more extensive support for color modeling than we have the space to discuss in this book, so if you want to know more, look in the classes of the java.awt.color package.

When you want to define an image to be transparent to some degree, so that when it is displayed on top of a background image the underlying image shows through, you can specify the degree of transparency by something called an alpha component for each pixel. An image format that has an alpha component for each pixel is said to have an alpha channel. Note that not all image formats support an alpha channel, but PNG files do, and GIF images can have a single transparent color. The alpha component value is used when an image is being overlaid by another image. The alpha value is multiplied by each of the color components to modify the contribution of each color component to the visual appearance of the pixel. The alpha value for a pixel in an image can vary from a minimum of 0.0, meaning completely transparent and therefore invisible since all the color components will be 0, to a maximum of 1.0, meaning completely opaque. In an RGB image with an alpha channel, each pixel is defined by four components, the three color components, red, green and blue, plus the alpha component. This allows the transparency to vary over the image, so some parts of the image could be opaque – with an alpha component of 1.0, and other parts may be more or less transparent, with alpha components for the pixels less than 1.0. It's worth noting that both the source image, the image that you are drawing, and the destination image, the background in other words, can have an alpha channel. If an image has no alpha channel, then the alpha component is assumed to be 1.0.

When you draw a source image over a destination image, there are basically two steps to the process. The color components for each pixel in the source image and the corresponding pixels in the destination image will be multiplied by their alpha component – often this will be done once and for all ahead of time for an image to avoid all those multiplications each time you draw an image. The source image is then rendered over the destination image according to the alpha compositing rule that is in effect. There are several alpha compositing rules as we shall see, but they each determine the fraction of the source image components and the fraction of the destination image components that contribute to the components of the result. In general, the components of the source and destination pixels are combined as follows:

ColorR = ColorS*AlphaS*FractionS + ColorD*AlphaD*FractionD
AlphaR = AlphaS*FractionS +AlphaD*FractionD

The first equation applies to each of the three color components. The subscripts R, S, and D refer to the resultant pixel, the source pixel and the destination pixel, respectively. Thus, ColorR refers to the color of the resultant pixel produced by combining the source and the destination, AlphaS refers to the alpha component for the source pixel and FractionS represents the fraction of the source pixel determined by the compositing rule in effect.

This sounds a lot more complicated than it really is, so don't be put off by these equations. The alpha compositing rules that you can use in Java are implemented by the AlphaComposite class that is defined in the java.awt package. The Graphics2D class defines the method setComposite() that takes an AlphaComposite argument in order to set the alpha compositing rule to be used when you draw in the graphics context. Let's take a look at the AlphaComposite class in more detail.

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.

XML error: undefined entity at line 19
advertisement
Receive Articles via our XML/RSS feed
Receive Articles via our XML/RSS feed

JavaBytes
Internet Cyclone
This powerful, easy-to-use, internet optimizer is for Windows 95, 98, ME, NT, 2000 and XP. It's designed to automatically optimize your Windows settings, boosting your Internet connection up to 200%.

Linux Vendors Head to the Cloud in Search of Cash
iPhone 3GS: Overheating Fears, OS Update Nears
PostgreSQL 8.4 Revs Up Database Admin, Security
PHP 5.3 Accelerates PHP
Sun Releases NetBeans 6.7 IDE for Java, PHP
Why Firefox Doesn't Take Google Chrome Features
First Major PHP Update in Years Coming Soon
Red Hat CEO Calls on Oracle to Keep Java Open
Google Widens AdSense for iPhone, Android Apps
Eclipse Galileo Releases 33 Open Source Projects

A Taste of JavaFX for the Uninitiated
A Guide to Caching and Compression for High Performance Web Applications
How User-Centered Design Can Put User Stories in Proper Context
Explore C# 4's New Dynamic Types and Named/Optional Parameters
Enterprise Architecture: The Journey Begins Here, Part 2
Create a Syslog Sender/Receiver Using the MS Winsock Control
AMD CodeAnalyst Helps Developers Optimize and Tune Applications
Securing Microsoft's Cloud Infrastructure
Introducing the Azure Services Platform
An Introduction to Microsoft .NET Services for Developers

Advertising Info  |   Member Services  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs