X-Git-Url: https://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=tim%2Fprune%2Fgui%2FImageUtils.java;h=c3c4c2088d796e71d9ca2bcf9aaec1c6f35b9076;hp=3fa7a1a8fdb2ca822f4a7e226d7459f3b80eca5c;hb=92dad5df664287acb51728e9ea599f150765d34a;hpb=1ee49ae3c8ef3aa2e63eadd458531e5f8bd4f92c diff --git a/tim/prune/gui/ImageUtils.java b/tim/prune/gui/ImageUtils.java index 3fa7a1a..c3c4c20 100644 --- a/tim/prune/gui/ImageUtils.java +++ b/tim/prune/gui/ImageUtils.java @@ -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); }