Here you can find the source of drawImage(Graphics2D g2d, BufferedImage image, Rectangle dispArea)
public static void drawImage(Graphics2D g2d, BufferedImage image, Rectangle dispArea)
//package com.java2s; //License from project: Apache License import java.awt.*; import java.awt.image.*; public class Main { public static void drawImage(Graphics2D g2d, BufferedImage image, Rectangle dispArea) { int wt = image.getWidth(); int ht = image.getHeight(); int x = dispArea.x + (int) ((dispArea.width - wt) / 2); int y = dispArea.y + (int) ((dispArea.height - ht) / 2); g2d.drawImage(image, x, y, wt, ht, null); }//from w ww .j a va2 s. c o m }