]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - tim/prune/gui/ImageUtils.java
Version 19, May 2018
[GpsPrune.git] / tim / prune / gui / ImageUtils.java
index 3fa7a1a8fdb2ca822f4a7e226d7459f3b80eca5c..c3c4c2088d796e71d9ca2bcf9aaec1c6f35b9076 100644 (file)
@@ -39,6 +39,9 @@ public abstract class ImageUtils
         */
        public static BufferedImage createScaledImage(Image inImage, int inWidth, int inHeight)
        {
+               if (inWidth <= 0 || inHeight <= 0) {
+                       return null;
+               }
                // create smaller image and force its loading
                Image smallerImage = inImage.getScaledInstance(inWidth, inHeight, Image.SCALE_SMOOTH);
                Image tempImage = new ImageIcon(smallerImage).getImage();
@@ -70,15 +73,19 @@ public abstract class ImageUtils
         */
        public static Dimension getThumbnailSize(int inOrigWidth, int inOrigHeight, int inMaxWidth, int inMaxHeight)
        {
-               assert(inMaxWidth > 0 && inMaxHeight > 0);
+               if (inMaxWidth <= 0 || inMaxHeight <= 0) {return new Dimension(1, 1);}
                // work out maximum zoom ratio available so that thumbnail isn't too big
                double xZoom = inMaxWidth * 1.0 / inOrigWidth;
                double yZoom = inMaxHeight * 1.0 / inOrigHeight;
                double zoom = (xZoom > yZoom?yZoom:xZoom);
                // Don't make thumbnail bigger than picture
                if (zoom > 1.0) {return new Dimension(inOrigWidth, inOrigHeight);}
+
                // calculate new width and height
-               return new Dimension ((int) (zoom * inOrigWidth), (int) (zoom * inOrigHeight));
+               final int xSize = (int) (zoom * inOrigWidth);
+               final int ySize = (int) (zoom * inOrigHeight);
+               if (xSize <= 0 || ySize <= 0) {return new Dimension(1, 1);}
+               return new Dimension (xSize, ySize);
        }