Here you can find the source of drawImageClip(Graphics g, BufferedImage image, ImageObserver observer)
public static void drawImageClip(Graphics g, BufferedImage image, ImageObserver observer)
//package com.java2s; import java.awt.*; import java.awt.image.BufferedImage; import java.awt.image.ImageObserver; public class Main { /**//from w w w .ja v a2 s .c om * Draws the image inside the clip bounds to the given graphics object. */ public static void drawImageClip(Graphics g, BufferedImage image, ImageObserver observer) { Rectangle clip = g.getClipBounds(); if (clip != null) { int w = image.getWidth(); int h = image.getHeight(); int x = Math.max(0, Math.min(clip.x, w)); int y = Math.max(0, Math.min(clip.y, h)); w = Math.min(clip.width, w - x); h = Math.min(clip.height, h - y); if (w > 0 && h > 0) { // TODO: Support for normal images using fast subimage copies g.drawImage(image.getSubimage(x, y, w, h), clip.x, clip.y, observer); } } else { g.drawImage(image, 0, 0, observer); } } }