0

Namastey,

I want to change those black color pixels to transparent pixels in a bitmap. my bitmap looks like below image.

I have tried to change those black pixels by below code. but it's not working for me.

    int [] allpixels = new int [maskImage.getHeight()*maskImage.getWidth()];
    maskImage.getPixels(allpixels, 0, maskImage.getWidth(), 0, 0, maskImage.getWidth(), maskImage.getHeight());
    for(int i = 0; i < allpixels.length; i++){
        if(allpixels[i] == Color.BLACK){
            allpixels[i] = Color.TRANSPARENT;
        }
    }
    maskImage.setPixels(allpixels, 0, maskImage.getWidth(), 0, 0, maskImage.getWidth(), maskImage.getHeight());

is it possible to do so? if yes, how can i do that?

enter image description here

Mayur Gadhiya
  • 119
  • 2
  • 13

1 Answers1

-1

Use this code, will work like a charm:

int [] allpixels = new int [myBitmap.getHeight()*myBitmap.getWidth()]; myBitmap.getPixels(allpixels, 0, myBitmap.getWidth(), 0, 0, myBitmap.getWidth(), myBitmap.getHeight());

for(int i = 0; i < allpixels.lenght; i++)

{ 
if(allpixels[i] == Color.BLACK)
{ 
    allpixels[i] = Color.RED;
} 

}

myBitmap.setPixels(allpixels, 0, myBitmap.getWidth(), 0, 0, myBitmap.getWidth(),
myBitmap.getHeight());

ubhusri
  • 52
  • 5