1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 02:37:36 +00:00

PixelPaint: adding an option to export as PNG

This commit is contained in:
Pierre 2021-01-22 11:55:26 +01:00 committed by Andreas Kling
parent a1d7739607
commit 8e265b512a
3 changed files with 29 additions and 0 deletions

View file

@ -34,6 +34,7 @@
#include <LibGUI/Painter.h>
#include <LibGfx/BMPWriter.h>
#include <LibGfx/ImageDecoder.h>
#include <LibGfx/PNGWriter.h>
#include <stdio.h>
//#define PAINT_DEBUG
@ -153,6 +154,19 @@ void Image::export_bmp(const String& file_path)
fclose(file);
}
void Image::export_png(const String& file_path)
{
auto bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::RGBA32, m_size);
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 file = fopen(file_path.characters(), "wb");
fwrite(png.data(), sizeof(u8), png.size(), file);
fclose(file);
}
void Image::add_layer(NonnullRefPtr<Layer> layer)
{
for (auto& existing_layer : m_layers) {