Closed g40 closed 6 months ago
BGR -> RGB
Indeed. That could explain it. But there is not much space in this code in which to make such a mistake:
filename = "tiger.svg";
auto document = lunasvg::Document::loadFromFile(filename);
auto bitmap = document->renderToBitmap(width, height, bgColor);
filename += _T(".png");
stbi_write_png(filename.c_str(), bitmap.width(), bitmap.height(), 4, bitmap.data(), 0);
Certainly, it looks like adding bitmap.convertToRGBA();
before saving the PNG would ensure the correct format. Here's the adjusted code:
filename = "tiger.svg";
auto document = lunasvg::Document::loadFromFile(filename);
auto bitmap = document->renderToBitmap(width, height, bgColor);
bitmap.convertToRGBA(); // Add this line to ensure correct format
filename += _T(".png");
stbi_write_png(filename.c_str(), bitmap.width(), bitmap.height(), 4, bitmap.data(), 0);
This should help ensure that the bitmap is in the RGBA format before saving it as a PNG.
@sammycage Thank you. It's just slightly confusing.
What is the native internal color format then? Does it vary according to platform?
For example, https://github.com/g40/lunasvg/blob/master/svg2png.cpp calls bitmap.convertToRGBA()
which implies something else.
Building the latest using VS2022 on Windows 10x64, svg2png produces the image below. Most odd, any thoughts?