From c8e88fb5687d2ea0beae5157d0c651da738aac10 Mon Sep 17 00:00:00 2001 From: nathan Date: Sun, 3 Sep 2017 15:15:31 +0200 Subject: [PATCH] Cleaned up image resizing --- .../systemTray/util/ImageResizeUtil.java | 20 +++---------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/src/dorkbox/systemTray/util/ImageResizeUtil.java b/src/dorkbox/systemTray/util/ImageResizeUtil.java index bd7f718..8746f96 100644 --- a/src/dorkbox/systemTray/util/ImageResizeUtil.java +++ b/src/dorkbox/systemTray/util/ImageResizeUtil.java @@ -223,30 +223,16 @@ class ImageResizeUtil { // resize the image, keep aspect ratio Image image = ImageUtil.getImageImmediate(ImageIO.read(inputStream)); - int height = image.getHeight(null); - int width = image.getWidth(null); - - if (width > height) { - // fit on the width - image = image.getScaledInstance(size, -1, Image.SCALE_SMOOTH); - } else { - // fit on the height - image = image.getScaledInstance(-1, size, Image.SCALE_SMOOTH); - } + // the smaller dimension have padding, so the larger dimension is the size of this image. + BufferedImage bufferedImage = ImageUtil.getSquareBufferedImage(image); // now write out the new one - BufferedImage bufferedImage = ImageUtil.getSquareBufferedImage(image); ImageIO.write(bufferedImage, "png", newFile); // made up extension return newFile; } - - - - - public static File shouldResizeOrCache(final boolean isTrayImage, final File imageFile) { if (imageFile == null) { @@ -324,8 +310,8 @@ class ImageResizeUtil { try { final Image trayImage = ImageUtil.getImageImmediate(image); - BufferedImage bufferedImage = ImageUtil.getBufferedImage(trayImage); + ByteArrayOutputStream os = new ByteArrayOutputStream(); ImageIO.write(bufferedImage, "png", os); InputStream imageInputStream = new ByteArrayInputStream(os.toByteArray());