Java examples for 2D Graphics:Image
draw Icon To Image Repeatedly
//package com.java2s; import java.awt.*; import javax.swing.ImageIcon; import java.awt.image.BufferedImage; public class Main { private static byte tileWidth = 64; private static byte tileHeight = 64; public static BufferedImage drawIconToImageRepeatedly( BufferedImage canvas, ImageIcon paint) { // Convert the "canvas" param to a BufferedImage so it can be manipulated Graphics g = canvas.createGraphics(); // Draw the "paint" on the "canvas" until the entire canvas is covered for (int row = 0; row < canvas.getWidth() / tileWidth; row++) { for (int col = 0; col < canvas.getHeight() / tileHeight; col++) { g.drawImage(paint.getImage(), row * tileWidth, col * tileHeight, null); }//from w w w. ja v a 2s. c o m } // Return the modified BufferedImage return canvas; } }