Here you can find the source of getResize(Image image, Dimension windowSize)
Parameter | Description |
---|---|
image | the source image |
windowSize | maximum space to fit the image |
public static double[] getResize(Image image, Dimension windowSize)
//package com.java2s; //License from project: Open Source License import java.awt.Dimension; import java.awt.Image; public class Main { /**//from w w w. j a v a 2 s . co m * @param image the source image * @param windowSize maximum space to fit the image * @return {width, height, used scale} */ public static double[] getResize(Image image, Dimension windowSize) { double w = image.getWidth(null); double h = image.getHeight(null); double f = 1; double fw = w / windowSize.getWidth(); double fh = h / windowSize.getHeight(); if (fw > 1 || fh > 1) { if (fh > fw) { w /= fh; h = windowSize.getHeight(); f = fh; } else { w = windowSize.getWidth(); h /= fw; f = fw; } } return new double[] { w, h, 1 / f }; } }