[an error occurred while processing this directive]
[an error occurred while processing this directive]

AC20: Alpha Compositing

The purpose of this activity is to get some hands-on experience with alpha compositing rules. You will need to download http://courses.csail.mit.edu/6.831/handouts/ac20/AlphaCompositing.java, which is the Java code you'll be using, and build it with Eclipse or javac.

1 Getting Started

Run the Java program and look carefully at the first two instances of the word "graphics". One is antialiased, and one is not. Make sure you can see the difference.

Read the source code of the BaseImage class. Why does it create a BufferedImage?

2 Dimming Out

The third line of the window is supposed to dim out the word "graphics" (as it might appear if it were a disabled icon), but not its background.

Uncomment the alpha compositing rule in the definition of Dimmed.paintEffect() and choose the appropriate rule so that only the word "graphics" is dimmed. Don't change any other code. See the AlphaComposite documentation for the Java names of the compositing rules.

3 Filling in Background

The fourth line of the window is supposed to paint a light blue background behind the word "graphics", like the image below. Instead it's painting over the top. Add an alpha compositing rule to Background.paintEffect() so that it works, without changing any other code.

4 Fading

The last line of the window is supposed to show "graphics" fading out from top to bottom, like the image below. Before trying this, study the call to GradientPaint in Fading.paintEffect(). What does it do?

Now add an alpha compositing rule so that the last line looks right, without changing any other code.

Alpha compositing examples

[an error occurred while processing this directive]