Here you can find the source of drawImage(BufferedImage target, Point targetPoint, BufferedImage source)
public static void drawImage(BufferedImage target, Point targetPoint, BufferedImage source)
//package com.java2s; //License from project: Open Source License import java.awt.Point; import java.awt.Rectangle; import java.awt.image.BufferedImage; public class Main { public static void drawImage(BufferedImage target, Point targetPoint, BufferedImage source) { Rectangle area = new Rectangle(0, 0, source.getWidth(), source.getHeight()); drawImage(target, targetPoint, source, area); }/* www . j a va 2 s . c o m*/ public static void drawImage(BufferedImage target, Point targetPoint, BufferedImage source, Rectangle sourceArea) { Rectangle copyFrom = (Rectangle) sourceArea.clone(); Rectangle copyTo = new Rectangle(targetPoint.x, targetPoint.y, sourceArea.width, sourceArea.height); int d; if (copyTo.x < 0) { d = copyTo.x - 0; copyTo.x -= d; copyTo.width += d; copyFrom.x -= d; copyFrom.width += d; } if (copyTo.y < 0) { d = copyTo.y - 0; copyTo.y -= d; copyTo.height += d; copyFrom.y -= d; copyFrom.height += d; } if (copyTo.x + copyTo.width > target.getWidth()) { d = copyTo.x + copyTo.width - target.getWidth(); copyTo.width -= d; copyFrom.width -= d; } if (copyTo.y + copyTo.height > target.getHeight()) { d = copyTo.y + copyTo.height - target.getHeight(); copyTo.height -= d; copyFrom.height -= d; } int i = copyTo.x; int j = copyTo.y; int x1 = copyFrom.x; int y1 = copyFrom.y; int x2 = copyFrom.x + copyFrom.width; int y2 = copyFrom.y + copyFrom.height; for (int x = x1; x < x2; ++x) { for (int y = y1; y < y2; ++y) { target.setRGB(i, j++, source.getRGB(x, y)); } ++i; j = copyTo.y; } } }