1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 05:27:43 +00:00

PixelPaint: Add Copy Merged action

This allows the user to copy the merged bitmap (all visible layers).
This commit is contained in:
Mustafa Quraish 2021-09-03 07:38:45 -04:00 committed by Andreas Kling
parent 65d52467f4
commit 6910cbc075
3 changed files with 32 additions and 0 deletions

View file

@ -8,6 +8,7 @@
#include "Image.h"
#include "Layer.h"
#include "Selection.h"
#include <AK/Base64.h>
#include <AK/JsonObject.h>
#include <AK/JsonObjectSerializer.h>
@ -173,6 +174,20 @@ RefPtr<Gfx::Bitmap> Image::try_compose_bitmap(Gfx::BitmapFormat format) const
return bitmap;
}
RefPtr<Gfx::Bitmap> Image::try_copy_bitmap(Selection const& selection) const
{
if (selection.is_empty())
return {};
auto selection_rect = selection.bounding_rect();
// FIXME: Add a way to only compose a certain part of the image
auto full_bitmap = try_compose_bitmap(Gfx::BitmapFormat::BGRA8888);
if (!full_bitmap)
return {};
return full_bitmap->cropped(selection_rect);
}
Result<void, String> Image::export_bmp_to_fd_and_close(int fd, bool preserve_alpha_channel)
{
auto file = Core::File::construct();