Here you can find the source of chunk(BufferedImage image)
public static void chunk(BufferedImage image) throws IOException
//package com.java2s; //License from project: Open Source License import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.io.*; import java.awt.*; public class Main { private static int rows = 2; private static int cols = 2; public static void chunk(BufferedImage image) throws IOException { int chunks = rows * cols; int chunkWidth = image.getWidth() / cols; // determines the chunk width and height int chunkHeight = image.getHeight() / rows; int count = 0; BufferedImage imgs[] = new BufferedImage[chunks]; //Image array to hold image chunks for (int x = 0; x < rows; x++) { for (int y = 0; y < cols; y++) { //Initialize the image array with image chunks imgs[count] = new BufferedImage(chunkWidth, chunkHeight, image.getType()); // draws the image chunk Graphics2D gr = imgs[count++].createGraphics(); gr.drawImage(image, 0, 0, chunkWidth, chunkHeight, chunkWidth * y, chunkHeight * x, chunkWidth * y + chunkWidth, chunkHeight * x + chunkHeight, null); gr.dispose();/*from w w w . java 2 s.c o m*/ } } System.out.println("Splitting done"); //writing mini images into image files for (int i = 0; i < imgs.length; i++) { ImageIO.write(imgs[i], "jpg", new File("tmp/img" + i + ".jpg")); } System.out.println("Mini images created"); } }