The transparent pixels in my Bitmap shown as white

221 views Asked by At

I'm using c code to get frame from a gif file and it's working fine using ffmpeg library av_read_frame, then I convert the returned image from this format BGRA to ARGB format using this method libyuv::ABGRToARGB.

In the java part I receive the bitmap and when I put it in the ImageView the transparent pixels drawn white.

 Bitmap bitmap= Bitmap.createBitmap(150, 150, Bitmap.Config.ARGB_8888);
 getGifFrame(gifFile,bitmap); //native method which get image frame from gif file.
 imageTest.setImageBitmap(backgroundBitmap);//this bitmap in debug mode I can see that it has transparent pixels, but in drawn it appears white!

even when I loop on the returned bitmap pixels and check for each pixel I find them transparent!

          for (int x = 0; x < b.getWidth(); x++)
            {
                for (int y = 0; y < b.getHeight(); y++)
                {
                    int color = b.getPixel(x, y);
                    if (color == Color.WHITE)//This condition never occurred 
                    {
                        b.setPixel(x, y, Color.TRANSPARENT);
                    }
                }
            }

Nothing happened and it's still white. Then I did convert all transparent pixels to TRANSPARENT !! and guess what, It's working!

else if (color == Color.TRANSPARENT)
{
  b.setPixel(x, y, Color.TRANSPARENT);
}

I don't understand why that happen. Any help would be appreciated.

EDIT 1: I get all pixels from the bitmap and set them again without doing anything and it worked also!?

  bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
  bitmap.setPixels(pixels, 0, width, 0, 0, width,height);
0

There are 0 answers