Search code examples
androidpngalpha-transparency

Saving PNG Drawable Android


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.


Solution

  • 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();