Here you can find the source of paintTexture(BufferedImage pattern, BufferedImage template)
public static BufferedImage paintTexture(BufferedImage pattern, BufferedImage template)
//package com.java2s; //License from project: Open Source License import java.awt.AlphaComposite; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.image.BufferedImage; public class Main { public static BufferedImage paintTexture(BufferedImage pattern, BufferedImage template) { BufferedImage repainted = new BufferedImage(template.getWidth(), template.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics g = repainted.getGraphics(); int width = pattern.getWidth(); int height = pattern.getHeight(); for (int x = 0; x < template.getWidth(); x++) for (int y = 0; y < template.getHeight(); y++) { float alpha = ((float) (template.getRGB(x, y) >>> 24) / 255F); int px = x % width; int py = y % height; AlphaComposite ac = java.awt.AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha); ((Graphics2D) g).setComposite(ac); g.drawImage(pattern, x, y, x + 1, y + 1, px, py, px + 1, py + 1, null); }//from w w w . ja va2s .c o m return repainted; } }