ColorMatrixColorFilter does not apply alpha android

477 Views Asked by At

I am trying to store the bitmap with Alpha value along with RGB all the color and shade apply except Alpha effect with value > 1.0 in ColorMatrix.

Below is my code

Bitmap bm = BitmapFactory.decodeFile(imagePath).copy(Config.ARGB_8888, true);

    final Bitmap b = Bitmap.createBitmap(bm.getWidth(), bm.getHeight(),
            Bitmap.Config.ARGB_8888);
    b.eraseColor(Color.argb(0, 0, 0, 0));
    final Canvas c = new Canvas(b);

    float redValue = ((float) red) / 255;
    float greenValue = ((float) green) / 255;
    float blueValue = ((float) blue) / 255;
    float alphaValue = ((float) alpha) / 255;

    ColorMatrix cm = new ColorMatrix();

    cm.set(new float[] { redValue, 0, 0, 0,0,
            0, greenValue, 0, 0, 0,
            0, 0, blueValue, 0, 0,
            0, 0, 0, alphaValue, 0 });

    Log.e("cm","cm::"+cm.toString());

    Paint p = new Paint();

    p.setColorFilter(new ColorMatrixColorFilter(cm));
    c.drawBitmap(bm, 0, 0, p);

return b;

Your suggestion/help will be appreciated

0

There are 0 best solutions below