This code draws a single color (with alpha) shape using a bitmap’s alpha channel.
Bitmap alphaMask = bitmap.extractAlpha();
Paint paint = new Paint();
int color = Color.GRAY;
...
paint.setColor(color);
paint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.DST_IN));
...
canvas.drawBitmap(alphaMask, x, y, paint);
For example, it will take the left Bitmap and draw it onto the canvas like it appears on the right:

However, it does not work on Honeycomb (Android 3.0) when hardware acceleration is turned on. It draws the shape as black no matter what. It ignores the color value. However, it works just fine on ICS (Android 4.0) with hardware acceleration on.
I know some API’s are not supported with hardware acceleration, as Romain Guy documented here, under What drawing operations are supported?, but I don’t appear to be using any of the ones mentioned as not supported.
Additionally, it sounded like he said that setColorFilter should work at this post.
Is there something in my code that is not supported in Honeycomb? Any workarounds? I would love to leave hardware acceleration on in this case.
Thanks
There was a bug with how Android 3.0 handled alpha8 bitmaps. I am terribly sorry for this since it was entirely my fault. This issue was however fixed in Android 4.0.
There are two possible workarounds:
– Set a software layer type on your view
– Or create your own Bitmap and render what you need in it. You can then draw this bitmap on top of the hardware accelerated Canvas.