+
+ /**
+ * Resize the given image.
+ *
+ * @param areaSize
+ * the base size of the target dimension for snap sizes
+ * @param image
+ * the image to resize
+ * @param zoom
+ * the zoom factor or -1 for snap size
+ * @param zoomSnapWidth
+ * if snap size, TRUE to snap to width (and FALSE, snap to
+ * height)
+ *
+ * @return a new, resized image
+ */
+ public static BufferedImage scaleImage(Dimension areaSize,
+ BufferedImage image, double zoom, boolean zoomSnapWidth) {
+ Integer scaledSize[] = scaleSize(areaSize.width, areaSize.height,
+ image.getWidth(), image.getHeight(), zoom, zoomSnapWidth);
+ int width = scaledSize[0];
+ int height = scaledSize[1];
+ BufferedImage resizedImage = new BufferedImage(width, height,
+ BufferedImage.TYPE_4BYTE_ABGR);
+ Graphics2D g = resizedImage.createGraphics();
+ try {
+ g.drawImage(image, 0, 0, width, height, null);
+ } finally {
+ g.dispose();
+ }
+
+ return resizedImage;
+ }