Statically Typed

because Hindley-Milner rocks

Android Alpha Blending and Canvas.drawColor


In my last post I was thrilled that something unexpected came out looking good.  I could see using what I’d done as a fader or for dramatic effect in an application.  In fact, my excitement was less about what had happened in comparison to what I could do with it.

So why did it occur?  Those that have programmed in a UI environment or worked with OpenGL can answer that question quickly, Alpha Blending.  It seems that the default blending scheme used by Android is not an “overwrite” setting but rather a “blend” setting.  Here’s a visual presentation of what each of those schemes looks like when composing bitmaps in successive order interspersed with calls to Canvas.drawColor:

  • CLEAR, DST_ATOP, DST_IN, MULTIPLY, SCREEN, SRC, SRC_IN, SRC_OUT – functions as an overwrite, clearing the entire Canvas before redrawing the bitmap.

  • DARKEN, DST, DTS_OUT, DST_OVER, LIGHTEN, SRC_ATOP, XOR – no discernible effect.  It’s as if nothing has been called at all.

  • SRC_OVER – the fading effect as shown by my last post.

How about if we use a different color in the call to Canvas.drawColor?  Is it the fact that I’ve used black which is having such a profound effect?

  • CLEAR, DST_OUT,  SRC_OUT, XOR – overwriting the same as CLEAR using the black color.  See picture above.
  • DARKEN, MULTIPLY – turns the previously drawn bitmaps green while leaving the screen black and the newest bitmap unaffected.

  • DST, DST_ATOP, DST_IN, DST_OVER – no discernible effect like DST with a black color.  See picture above.
  • LIGHTEN, SCREEN – sets the background to green, colors the previously drawn bitmaps a very light green, and finally leaves the newest draw bitmap alone

  • SRC, SRC_ATOP, SRC_IN, SRC_OVER – overwrite in the same way as CLEAR except turns the background green

So there you have it.  Background color does play an important role in how the alpha blending is applied with respect to this one function call.  I’ll start playing around with clipped portions of the canvas and see what effects I can uncover there.  In the meantime I hope you enjoyed this post.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Information

This entry was posted on December 18, 2010 by in Android, Java and tagged .
%d bloggers like this: