Skip to content

How to set background color to fill transparency in PNG #454

Discussion options

You must be logged in to vote

I couldn't tell you where the red background is coming from without a repo example.

JPG doesn't support alpha transparency, so the alpha from the PNG would just be ignored.

If you want to make sure the transparency of the PNG is put onto a specific color background, you could composite it onto a background image with a solid color. Something like:

final finalImage = Image(pngImage.width, pngImage.height); // This image will not have an alpha because numChannels is 3 by default.
finalImage.clear(ColorRgb8(255, 255, 255)); // white, but set it to what you want the transparency background to be
compositeImage(finalImage, pngImage); // alpha composite the PNG onto the background color image
/…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by VeryazovSergey
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants