import java.awt.Graphics; import java.awt.image.BufferedImage; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import javax.imageio.ImageIO; import javax.swing.ImageIcon; public class App { /** * @param args */ public static void main(String[] args) { ImageIcon icon = new ImageIcon("res/1.png"); int width = icon.getIconWidth(); int height = icon.getIconHeight(); int tWidth = 80; int tHeight = 60; File file; for (int i = 0; i < width / tWidth; i++) { for (int j = 0; j < height / tHeight; j++) { BufferedImage tempImg = new BufferedImage(tWidth, tHeight, BufferedImage.TYPE_INT_ARGB_PRE); Graphics g = tempImg.getGraphics(); g.drawImage(icon.getImage(), 0 - i * tWidth, 0 - j * tHeight, null); file = new File(System.getProperty("user.dir") + "/output/w" + i + "_h" + j + ".PNG"); file.mkdirs(); if (file.exists()) { file.delete(); } try { file.createNewFile(); ImageIO.write(tempImg, "PNG", file); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } } }