Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
483 views
in Technique[技术] by (71.8m points)

android - How to change the background color of a saved transparent bitmap

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?

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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, 0F, 0F, null);

then save new bitmap instead


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...