I've been trying to draw an ALPHA_8 bitmap with the alpha channel
giving a grayscale value.  The fairly obvious thing to do is to set up
a paint with ColorMatrixColorFilter that does the following
transformation:
 r' = a
 g' = a
 b' = a
 a' = 1
>From the documentation, it seems I should use this matrix:
 0 0 0 1 0
 0 0 0 1 0
 0 0 0 1 0
 0 0 0 0 1.
But when I do that, nothing shows up (I'm testing on an Archos 43 with
Android 2.2).  I think Canvas.drawBitmap() is drawing a bitmap with
zero alpha.  If I change the matrix to:
 0 0 0 1 0
 0 0 0 1 0
 0 0 0 1 0
 0 0 0 1 0
then it shows up, but I think it should get the shading wrong (since
it will have non-constant alpha).

I tried copying the ALPHA_8 bitmap into an ARGB_8888 bitmap before
drawing, but that doesn't help.

Further experiments suggest that the 5th column of the matrix, which
is supposed to be added to the color values, simply gets ignored.  For
instance, the matrix
  -1 0  0 0 1
   0 -1 0 0 1
   0 0 -1 0 1
   0 0  0 1 0
should theoretically reverse the color, keeping alpha fixed: r'=1-r,
g'=1-g, b'=1-b, a'=a.  But in fact, when I draw a RGB_565 or ARGB_8888
bitmap using a paint with this color matrix, nothing shows up.  From
my experiments, I am pretty sure the last column is being ignored, and
the color transformation that I'm getting is r'=-r, g'=-g, b'=-b,
a'=a, and of course then r'g'b' gets clamped to zero.

Fortunately, in the code I only needed a color reverse on a matrix
with constant a=1, so instead I am using the kludgy matrix (which I
found somewhere on the web):
  -1 0  0 1 0
   0 -1 0 1 0
   0 0 -1 1 0
   0 0  0 1 0
This does r'=a-r, g'=a-g, b'=a-b, a'=a, and it all shows up, but of
course only works if I am drawing a bitmap with constant a=1.

For a final test, I tried using the matrix:
  0 0 0 0 1
  0 0 0 0 1
  0 0 0 0 1
  0 0 0 0 1
This should do r'=g'=b'=a'=1.  But in fact, nothing gets drawn.

The code that I used for a bunch of the tests is (with the kludgy
inverse matrix as my example):

                        Paint paint = new Paint();
                        float[] inverter = {
                        -1.0f, 0.0f, 0.0f, 1.0f, 0.0f,
                        0.0f, -1.0f, 0.0f, 1.0f, 0.0f,
                        0.0f, 0.0f, -1.0f, 1.0f, 0.0f,
                        0.0f, 0.0f, 0.0f, 1.0f, 0.0f
                        };
                        paint.setColorFilter(new
                        ColorMatrixColorFilter(new ColorMatrix(inverter)));
                        Bitmap b2 = b.copy(Bitmap.Config.ARGB_8888, false);
                        canvas.drawBitmap(b2, src, dst, paint);

Here, b is an RGB_565 matrix.  I did a couple of the tests with
directly drawing b, and a couple of the tests with drawing the
ARGB_8888 copy b2.  And of course without the filter it works fine
(whether with copy or original).

My only explanation for all this is that the last column of the color
matrix is being ignored.  Am I doing something wrong?  Is there a bug
in the OS?  Am I missing something really obvious?

If you want to see the full context of the code, it's here:
http://tinyurl.com/pageview-java

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to