How to set background color to fill transparency in PNG #454
-
Hi! So my task is to convert PNG to JPG for next operations, but PNG comes with transparency and after convert I recieve red color as "background" - How to set/change this color? Thank you |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
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
// whatever else you're going to do with the image
final jpg = encodeJpg(finalImage); // jpeg file data |
Beta Was this translation helpful? Give feedback.
-
Many thanks! This is exactly what I needed!
|
Beta Was this translation helpful? Give feedback.
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: