mirror of
https://github.com/RGBCube/serenity
synced 2025-05-23 19:15:07 +00:00
LibGUI: Thumbnail keep the aspect ratio of the original file.
This commit is contained in:
parent
e9de8a445f
commit
f85aa8462f
1 changed files with 7 additions and 1 deletions
|
@ -470,9 +470,15 @@ static RefPtr<Gfx::Bitmap> render_thumbnail(const StringView& path)
|
||||||
auto png_bitmap = Gfx::Bitmap::load_from_file(path);
|
auto png_bitmap = Gfx::Bitmap::load_from_file(path);
|
||||||
if (!png_bitmap)
|
if (!png_bitmap)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
|
double scale = min(32 / (double)png_bitmap->width(), 32 / (double)png_bitmap->height());
|
||||||
|
|
||||||
auto thumbnail = Gfx::Bitmap::create(png_bitmap->format(), { 32, 32 });
|
auto thumbnail = Gfx::Bitmap::create(png_bitmap->format(), { 32, 32 });
|
||||||
|
Gfx::Rect destination = Gfx::Rect(0, 0, (int)(png_bitmap->width() * scale), (int)(png_bitmap->height() * scale));
|
||||||
|
destination.center_within(thumbnail->rect());
|
||||||
|
|
||||||
Painter painter(*thumbnail);
|
Painter painter(*thumbnail);
|
||||||
painter.draw_scaled_bitmap(thumbnail->rect(), *png_bitmap, png_bitmap->rect());
|
painter.draw_scaled_bitmap(destination, *png_bitmap, png_bitmap->rect());
|
||||||
return thumbnail;
|
return thumbnail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue