1
votes

I know how to save an image with Bitmap.compress(), but I really want to save the image as a PNG with its alpha-transparency, and using Bitmap just kills my efforts. I can save it as a opaque PNG, but not as a transparent PNG file.

Is there any approach to this?

Thank you.

2
Have u tried using ARGB_8888 as the bitmap config?blessenm
How do I change the bitmap config?Charlie-Blake

2 Answers

6
votes

Had the same issue. Just call bitmap.setHasAlpha(true); before you call compress.

1
votes

Try this out. I haven't tested it but it should work.

Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
OutputStream stream = new FileOutputStream("/sdcard/test.png");
bitmap.compress(CompressFormat.PNG, 100, stream);
stream.close();