7

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.

Abhilasha
  • 929
  • 1
  • 17
  • 37
Umesh
  • 1,609
  • 1
  • 17
  • 28

2 Answers2

13

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);
thearti
  • 371
  • 2
  • 6
-1

Bitmap images do not support transparency. You should use a GIF or a PNG.

http://www.gimpchat.com/viewtopic.php?f=8&t=1290

Quintin Balsdon
  • 5,484
  • 10
  • 54
  • 95
  • 2
    GIF is not recommended on android. – WarrenFaith Jul 23 '12 at 09:02
  • actually i am using PNG. I want to fill color in image thats why converted into bitmap now same image with filled color i want.How i can extract only image without background from bitmap? – Umesh Jul 23 '12 at 09:05
  • 1
    Well, if you are using a Bitmap object you may want to try: http://stackoverflow.com/questions/7237915/replace-black-color-in-bitmap-with-red – Quintin Balsdon Jul 23 '12 at 09:12