Search code examples
androidimagepngbitmapfactory

Losing transparent background when downloading an external PNG image


I'm displaying an external image in an image view by fist downloading it like this:

bitmap = BitmapFactory.decodeStream((InputStream)new URL(url).getContent());

Then setting this bitmap to the ImageView like this:

imageView.setImageBitmap(bitmap);

This works all good except that one of the images is a PNG and I lose the transparent background when using the BitmapFactory.

Can anyone tell me how I can keep the transparent background?


Solution

  • not sure if this will help, but try following this advice and adding Options to make sure that your image is pulled in as ARGB_8888

    http://developer.android.com/reference/android/graphics/BitmapFactory.html#decodeFile(java.lang.String, android.graphics.BitmapFactory.Options)