Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 961
kmb64 Avatar asked Feb 22 '12 00:02

kmb64


People also ask

Why is my PNG exporting with a white background?

You can confirm that your file has been converted by pressing edit on the image on your device from the Apple Photos app (see below) If the background turns black then transparency has been maintained. If it stays white then the image has been converted to a JPG file.

Why are my PNGs not transparent?

Because when you download the PNG from the Previewer Window, the PNG LOSES the transparency information.

Can you export a PNG with a transparent background?

How To Export Layer as Transparent PNG: If you want to export anything in Photoshop as a transparent PNG, instead of going to the File menu and selecting 'Export As', right-click on any layer and select 'Export As' and then choose PNG and make sure Transparent is checked.

Why does the PNG still show the background?

If your PNG image is saved with a transparent background, it will appear with a black background in Brainshark. That is because transparency in images is not supported in Brainshark. As a workaround, you can either add in a plain background using an image editing program, or try to save the image as a JPG or GIF.


1 Answers

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)

like image 55
Yevgeny Simkin Avatar answered Sep 29 '22 18:09

Yevgeny Simkin