batuman
batuman

Reputation: 7304

Add transparency to Bitmap image

I have converted my color image to black and white as follow.

        //convert color to black&white
        private Bitmap convertColorIntoBlackAndWhiteImage(Bitmap orginalBitmap) {
            ColorMatrix colorMatrix = new ColorMatrix();
            colorMatrix.setSaturation(0);
            ColorMatrixColorFilter colorMatrixFilter = new ColorMatrixColorFilter(
                    colorMatrix);
            Bitmap blackAndWhiteBitmap = orginalBitmap.copy(Bitmap.Config.ARGB_8888, true);

            Paint paint = new Paint();
            paint.setColorFilter(colorMatrixFilter);

            Canvas canvas = new Canvas(blackAndWhiteBitmap);
            canvas.drawBitmap(blackAndWhiteBitmap, 0, 0, paint);        


            return blackAndWhiteBitmap;
        }

How can I add half transparency, about 50% transparency, to the black and white image? Thanks

Upvotes: 1

Views: 856

Answers (1)

Zulfiqar Chandio
Zulfiqar Chandio

Reputation: 263

BitmapDrawable bd =
    new BitmapDrawable(convertColorIntoBlackAndWhiteImage(bMap));
bd.setAlpha(50);
imageView1.setImageDrawable(bd);

Upvotes: 1

Related Questions