Do you want to give something back to this project? I'm interested in redesigning my java.net page. If you're any good at web design, please get in touch and help me give it a facelift.

AlphaComposites: Which Does What?

It seems like every 4 months or so I come across a particular problem that I want to solve using AlphaComposites. The problem is I'm a very visual person; the equations listed in the javadocs don't help me visualize what each composite actually looks like.

Here is an applet that demonstrates most of the possible variables at play:



This applet (source included) is available here.

Also there are several AlphaComposite types where it makes a huge difference whether you're rendering images vs shapes. In this applet if "Use Images" is selected then the shapes you see are first rendered in a BufferedImage, and then those images are rendered together.

That's all. This is a clean, short article -- as much for my benefit as anyone else's.

5 comments:

  1. applets are dead =)

    well, may be they are not, but if possible, can you provide a webstart version too?

    ReplyDelete
  2. for me applets are dead too :(

    ReplyDelete
  3. Applets are not my favorite things in the world: but they work and are very low-maintenance from my end.

    Can you sell me on the idea of providing webstart versions? (What is it about webstarts that you need that applets don't provide?)

    ReplyDelete
  4. This applet is very much alive and OK :)

    Why is there a difference between images and shapes? Is this a Java bug or feature?

    ReplyDelete
  5. I'm not sure, but I think it's a feature.

    Shapes should only affect pixels inside their shape. If they affected pixels outside the shape: this would ruin simple SrcOver painting operations.

    And it makes sense that when images are composited: every pixel should be taken into account.

    ... therefore: I think the current behavior is working as designed. The applet above highlights some strange side effects of these rules, but I can't think of any other rules to govern things by.

    (If you can, then maybe I'm mistaken and this is a bug?)

    ReplyDelete