summaryrefslogtreecommitdiff
path: root/Userland/Applications/PixelPaint
diff options
context:
space:
mode:
Diffstat (limited to 'Userland/Applications/PixelPaint')
-rw-r--r--Userland/Applications/PixelPaint/Image.cpp14
-rw-r--r--Userland/Applications/PixelPaint/Image.h1
-rw-r--r--Userland/Applications/PixelPaint/main.cpp14
3 files changed, 29 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) {
diff --git a/Userland/Applications/PixelPaint/Image.h b/Userland/Applications/PixelPaint/Image.h
index 63184b3ad3..858c2381e1 100644
--- a/Userland/Applications/PixelPaint/Image.h
+++ b/Userland/Applications/PixelPaint/Image.h
@@ -70,6 +70,7 @@ public:
void paint_into(GUI::Painter&, const Gfx::IntRect& dest_rect);
void save(const String& file_path) const;
void export_bmp(const String& file_path);
+ void export_png(const String& file_path);
void move_layer_to_front(Layer&);
void move_layer_to_back(Layer&);
diff --git a/Userland/Applications/PixelPaint/main.cpp b/Userland/Applications/PixelPaint/main.cpp
index df581829e6..9c054a67dd 100644
--- a/Userland/Applications/PixelPaint/main.cpp
+++ b/Userland/Applications/PixelPaint/main.cpp
@@ -160,6 +160,20 @@ int main(int argc, char** argv)
image_editor.image()->export_bmp(save_path.value());
},
window));
+ export_submenu.add_action(
+ GUI::Action::create(
+ "As PNG", [&](auto&) {
+ if (!image_editor.image())
+ return;
+
+ Optional<String> save_path = GUI::FilePicker::get_save_filepath(window, "untitled", "png");
+
+ if (!save_path.has_value())
+ return;
+
+ image_editor.image()->export_png(save_path.value());
+ },
+ window));
app_menu.add_separator();
app_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) {