Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change black background color of bitmap to transparent?

Tags:

android

bitmap

I am creating Bitmap using following code:

Bitmap bm= Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

But I want to change Background color from black to transparent because I want to use this object in another Activity also. I searched a lot but I am unable to find solution. Please help. Thanks in advance.

like image 609
Umesh Avatar asked Jul 23 '12 08:07

Umesh


People also ask

Can BMP images be transparent?

Raster file formats that support transparency include GIF, PNG, BMP, TIFF, TGA and JPEG 2000, through either a transparent color or an alpha channel. Most vector formats implicitly support transparency because they simply avoid putting any objects at a given point.


1 Answers

Of course the Bitmap created in mode ARGB_8888 supports transparency But the alpha channel is initially filled by 0xff, so bitmap is opaque. You have to clear the whole bitmap including the alpha channel like this:

Canvas c = new Canvas(bm);
c.drawColor(0, Mode.CLEAR);
like image 127
thearti Avatar answered Oct 13 '22 17:10

thearti