GraphicUtils.scaleImageIcon(): scale only if needed

This commit is contained in:
Sergey Ponomarev 2024-08-23 20:56:05 +03:00
parent 7eb44ca4cc
commit 97beb604fc

View File

@ -722,11 +722,17 @@ public final class GraphicUtils {
public static ImageIcon scaleImageIcon(ImageIcon icon, int newHeight, int newWidth) {
int height = icon.getIconHeight();
int width = icon.getIconWidth();
boolean resize = false;
if (height > newHeight) {
height = newHeight;
resize = true;
}
if (width > newWidth) {
width = newWidth;
resize = true;
}
if (!resize) {
return icon;
}
Image img = icon.getImage().getScaledInstance(width, height, Image.SCALE_SMOOTH);
return new ImageIcon(img);