Here you can find the source of drawImage(Image image, Dimension windowSize, Graphics graphics)
public static double[] drawImage(Image image, Dimension windowSize, Graphics graphics)
//package com.java2s; //License from project: Open Source License import java.awt.Dimension; import java.awt.Graphics; import java.awt.Image; public class Main { public static double[] drawImage(Image image, Dimension windowSize, Graphics graphics) { double size[] = getResize(image, windowSize); graphics.drawImage(image, 0, 0, (int) size[0], (int) size[1], null); return size; }/*from w ww. jav a 2 s.c o 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 }; } }