1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 11:28:11 +00:00

LibGfx: Improve PNG encoder API somewhat

This is still far from ideal, but let's at least make it take a
Gfx::Bitmap const&.
This commit is contained in:
Andreas Kling 2021-04-19 23:43:04 +02:00
parent 51fe25fdbb
commit 6793574003
4 changed files with 31 additions and 30 deletions

View file

@ -155,11 +155,11 @@ void Image::export_bmp(const String& file_path)
void Image::export_png(const String& file_path)
{
auto bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, m_size);
VERIFY(bitmap);
GUI::Painter painter(*bitmap);
paint_into(painter, { 0, 0, m_size.width(), m_size.height() });
Gfx::PNGWriter png_writer;
auto png = png_writer.write(bitmap);
auto png = Gfx::PNGWriter::encode(*bitmap);
auto file = fopen(file_path.characters(), "wb");
fwrite(png.data(), sizeof(u8), png.size(), file);
fclose(file);