如何更改保存的透明位图的背景颜色 [英] How to change the background color of a saved transparent bitmap
本文介绍了如何更改保存的透明位图的背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我打开PNG图像成位图,使得一些修改,然后将其保存到磁盘为JPG。在那里的PNG有一些透明区域的情况下,它们被保存为黑色。有没有办法改变这种默认行为,以便将图像保存为不同的背景颜色,如白色的?
I am opening a png image into a Bitmap, making some modifications to it and then saving it to disk as a jpg. In the case where the png has some transparent areas, they are saved as black. Is there a way to change this default behavior so the image is saved with a different color background such as white?
感谢
推荐答案
您可以画到一个新的位图,如:
You could draw it to a new bitmap, e.g.
Bitmap newBitmap = Bitmap.createBitmap(image.getWidth(), image.getHeight(), image.getConfig());
Canvas canvas = new Canvas(newBitmap);
canvas.drawColor(Color.WHITE);
canvas.drawBitmap(image, 0, 0, null);
然后保存newBitmap而不是
then save newBitmap instead
这篇关于如何更改保存的透明位图的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文