Saving PNG Drawable Android

China☆狼群 提交于 2020-01-05 08:31:29

问题


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.


回答1:


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



回答2:


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



来源:https://stackoverflow.com/questions/11518910/saving-png-drawable-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!