Here you can find the source of drawTiledImage(Rectangle2D bounds, Graphics2D g2, Image image, ImageObserver observer, int imageWidth, int imageHeight, int tilePadding)
public static void drawTiledImage(Rectangle2D bounds, Graphics2D g2, Image image, ImageObserver observer, int imageWidth, int imageHeight, int tilePadding)
//package com.java2s; import java.awt.Graphics2D; import java.awt.Image; import java.awt.geom.Rectangle2D; import java.awt.image.ImageObserver; public class Main { public static void drawTiledImage(Rectangle2D bounds, Graphics2D g2, Image image, ImageObserver observer, int imageWidth, int imageHeight, int tilePadding) { int x = (int) bounds.getX(); int y = (int) bounds.getY(); int w = imageWidth; int h = imageHeight; int cols = (int) Math.ceil(bounds.getWidth() / imageWidth); int rows = (int) Math.ceil(bounds.getHeight() / imageHeight); for (int row = 0; row < rows; row++) { if ((y + imageHeight) > bounds.getMaxY()) { h = (int) bounds.getMaxY() - y; }/*from w w w .j ava2s . co m*/ for (int col = 0; col < cols; col++) { w = imageWidth; if ((x + imageWidth) > bounds.getMaxX()) { w = (int) bounds.getMaxX() - x; } // no scaling g2.drawImage(image, x, y, x + w, y + h, 0, 0, w, h, observer); // move over a column x += w + tilePadding; } // go down a row y += h + tilePadding; x = (int) bounds.getX(); } } }