summaryrefslogtreecommitdiff
path: root/Userland/Applications/PixelPaint/Image.cpp
diff options
context:
space:
mode:
authorPierre <pierre.git@posteo.de>2021-01-22 11:55:26 +0100
committerAndreas Kling <kling@serenityos.org>2021-01-22 20:39:25 +0100
commit8e265b512a3385b8494187e05132d7be90c4a340 (patch)
tree457dfd33f94455edac0ba7f5ff89150e79824605 /Userland/Applications/PixelPaint/Image.cpp
parenta1d773960723dcd6395bef4c4e5eecf4fe3c68e3 (diff)
downloadserenity-8e265b512a3385b8494187e05132d7be90c4a340.zip
PixelPaint: adding an option to export as PNG
Diffstat (limited to 'Userland/Applications/PixelPaint/Image.cpp')
-rw-r--r--Userland/Applications/PixelPaint/Image.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/Userland/Applications/PixelPaint/Image.cpp b/Userland/Applications/PixelPaint/Image.cpp
index 09a075dfe0..01f202cce4 100644
--- a/Userland/Applications/PixelPaint/Image.cpp
+++ b/Userland/Applications/PixelPaint/Image.cpp
@@ -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) {