Reputation: 414
Is there a reason why the code below does not make any changes to the source bitmap mBitmap? mBitmap is a greyscale image that I would like to apply a color filter to. The filter itself is unimportant, but any color filter that I apply to it has no effect. What gets drawn to the screen is the original bitmap as though I applied no filter to it.
I can apply different color filters to it, such as:
mPaint.setColorFilter(new LightingColorFilter(Color.RED, 100));
But when I create a color filter from a color matrix, I get nothing.
I am using Android 2.3.
My Code:
float[] mat = new float[] {
1f, 0f, 0f, 0f, 1f,
2f, 0f, 2f, 1f, 0f,
1f, 1f, 0f, 0f, 0f,
0f, 0f, 0f, 1f, 0f,
2f, 0f, 0f, 0f, 1f };
ColorMatrix colorMatrix = new ColorMatrix(mat);
ColorMatrixColorFilter colorFilter = new ColorMatrixColorFilter(colorMatrix);
mPaint.setColorFilter(colorFilter);
mCanvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
mCanvas.drawBitmap(mBitmap, 0, 0, mPaint);
Upvotes: 2
Views: 4048
Reputation: 414
Apologies for asking this question. It was poorly formed due to my lack of understanding. for all I know that ColorMatrix above actually does nothing.
In short, my original problem stemmed from the fact that I was attempting to make a hue adjustment to a grayscale image. As it turns out: making a hue adjustment on a grayscale image has no meaning and therefore I was seeing no change.
The confusion came from this (excellent) question:
Understanding the Use of ColorMatrix and ColorMatrixColorFilter to Modify a Drawable's Hue
I assumed the asker was simply making a hue adjustment to a grayscale image, as he had originally asked. Now I know he must be making the hue adjustment to some previously colored image.
Ah well. The best form of learning comes from being forced to actually think about what you're trying to do!
Upvotes: 2