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

The AlphaComposite Class

There is no constructor for the AlphaComposite class, so you cannot create objects directly. There is a static class member, getInstance(), that will return a reference to an AlphaComposite object with the compositing rule specified by the argument, which is a value of type int. There is also an overloaded version of this method where you can specify an alpha value as a second argument of type float, which is multiplied by the alpha for the source image. This is particularly useful when the source image has no alpha channel. Since an image with no alpha channel has an alpha component that is assumed to be 1.0, the alpha value that you specify in the call to getInstance() becomes the alpha value for all the pixels in the source. Most of the time, your images will not have an alpha channel so this is a way for you to specify the transparency of the source image directly in the graphics context.

There are eight possible alpha compositing rules, determined by constants of type int that are defined in the AlphaComposite class. In reviewing these, we will assume that, if the source or destination image has an alpha channel, the color components, ColorS and ColorD, for each pixel have already been pre- multiplied by the alpha component, AlphaS or AlphaD respectively. In the illustration of the effect of each rule described below, the source image is the light gray circle, and this is rendered over the darker gray rectangle (the destination image). The source image has its alpha component set to 0.5f.

SRC_OVER

This is the default rule that applies in a graphics context and is the rule that you are most likely to be using. The fraction of the source that contributes to the result is 1, and the fraction of the destination contributing to the result is 1-AlphaS.Therefore from our general equations, the source pixels are combined with the corresponding destination pixels using the following operations:

ColorR = ColorS + (1-AlphaS)*ColorD
AlphaR = AlphaS + (1-AlphaS)*AlphaD

The calculation of the resultant color is applied to each of the red, green and blue components of each pixel. You can see from the equations above that if the alpha component for the source, AlphaS, is 1, then the fraction of the destination will be zero so the result is just the original source pixel – in other words the source is opaque. If the alpha component for the source is 0, then the result is just the destination pixel so the source is completely transparent and would be invisible. The illustration shows the source with an alpha of 0.5f so the destination shows through.

SRC

With this rule, the source pixels replace the destination pixels, so the operations determining the resultant color and alpha components for each pixel are:

  ColorR = ColorS
AlphaR = AlphaS

SRC_IN

With this rule, the fraction of the source in the result is the alpha for the destination, AlphaD, and the fraction of the destination in the result is zero. Thus only the source pixels that fall within the area destination image are rendered. All other pixels rendered from the source will have zero color components. As you can see, the outline of the destination image acts like a pastry cutter on the source image. The operations for the rule are:

ColorR = ColorS*AlphaD
AlphaR = AlphaS*AlphaD

SRC_OUT

With this rule, only the source pixels outside the area of the destination will be rendered. The outline of the destination image also acts like a pastry cutter here, but the source image inside the outline is discarded, and only the source image lying outside of the destination image is kept. The area of the source that lies inside the boundary of the destination results in pixels with color components that are zero. The calculation of the components of the result is defined as:

ColorR = ColorS*(1 - AlphaD)
AlphaR = AlphaS*(1 - AlphaD)

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.

 Microsoft Visual Studio 2010 Showcase
 Avaya Developer Showcase
 MSDN Spotlight
 PHP for Windows Showcase
XML error: undefined entity at line 39
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%.

Windows 7: From Beta to Final Code in One Year
Google Shows Off Chrome OS, Releases Source
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?
Fedora 12 Takes Aim at Linux Networking
Top Supercomputer Nearly Doubles in Speed
Fedora 12 Linux Tackles Virtualization
Apple Gives iPhone Developers App Status Tracker
Novell Sets OpenSUSE 11.2 Free

Creating Custom Export Filters for StarOffice with XSLT
WPF Wonders: Using DataTemplates
Crystal Reports Family Offers Options for Developers
Avaya Aura Session Manager video
Avaya Aura Overview video
Exploring HTML 5's Audio/Video Multimedia Support
Overriding Virtual Functions? Use C++0x Attributes to Avoid Bugs.
Understanding the Cloud Computing Security Vulnerabilities
Cisco and IBM Target a Greener World
Upgrade to Visual Studio 2010 with the Ultimate Offer

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, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs