ImageUtils: fix scale process
authorNiki Roo <niki@nikiroo.be>
Sun, 3 May 2020 20:12:36 +0000 (22:12 +0200)
committerNiki Roo <niki@nikiroo.be>
Sun, 3 May 2020 20:12:36 +0000 (22:12 +0200)
ImageUtils.java
ui/ImageUtilsAwt.java

index c0e123280cd5aa846bd57e08324a81df253c9de4..2b8ff8fa9ec722056904d310343761f979285924 100644 (file)
@@ -65,7 +65,7 @@ public abstract class ImageUtils {
                int width;
                int height;
                if (zoom > 0) {
-                       width = (int) Math.round(imageHeight * zoom);
+                       width = (int) Math.round(imageWidth * zoom);
                        height = (int) Math.round(imageHeight * zoom);
                } else {
                        if (zoomSnapWidth) {
index 9412c93cd93b52c00d4fbc33cc93dc8c9860c17a..2919d6b640c02ca2f0c5c7abab8ab5fb04f7829a 100644 (file)
@@ -37,6 +37,7 @@ public class ImageUtilsAwt extends ImageUtils {
                /** Rotate the image by 180° */
                UTURN
        }
+
        @Override
        protected boolean check() {
                // Will not work if ImageIO is not available
@@ -96,7 +97,7 @@ public class ImageUtilsAwt extends ImageUtils {
        public static BufferedImage fromImage(Image img) throws IOException {
                return fromImage(img, Rotation.NONE);
        }
-       
+
        /**
         * Convert the given {@link Image} into a {@link BufferedImage} object,
         * respecting the EXIF transformations if any.
@@ -112,7 +113,8 @@ public class ImageUtilsAwt extends ImageUtils {
         * @throws IOException
         *             in case of IO error
         */
-       public static BufferedImage fromImage(Image img, Rotation rotation) throws IOException {
+       public static BufferedImage fromImage(Image img, Rotation rotation)
+                       throws IOException {
                InputStream in = img.newInputStream();
                BufferedImage image;
                try {
@@ -146,8 +148,7 @@ public class ImageUtilsAwt extends ImageUtils {
                                                } finally {
                                                        inData.close();
                                                }
-                                               extra = ", content: "
-                                                               + new String(data, "UTF-8");
+                                               extra = ", content: " + new String(data, "UTF-8");
                                        } catch (Exception e) {
                                                extra = ", content unavailable";
                                        }
@@ -202,19 +203,19 @@ public class ImageUtilsAwt extends ImageUtils {
                                affineTransform = null;
                                break;
                        }
-                       
+
                        if (rotation == null)
                                rotation = Rotation.NONE;
-                       
+
                        switch (rotation) {
-                       case LEFT:
+                       case RIGHT:
                                if (affineTransform == null) {
                                        affineTransform = new AffineTransform();
                                }
                                affineTransform.translate(height, 0);
                                affineTransform.rotate(Math.PI / 2);
                                break;
-                       case RIGHT:
+                       case LEFT:
                                if (affineTransform == null) {
                                        affineTransform = new AffineTransform();
                                }
@@ -280,7 +281,7 @@ public class ImageUtilsAwt extends ImageUtils {
                } finally {
                        g.dispose();
                }
-               
+
                return resizedImage;
        }
 }