Here you can find the source of cutImage(String src, String dest, int x, int y, int w, int h)
public static void cutImage(String src, String dest, int x, int y, int w, int h) throws IOException
//package com.java2s; import javax.imageio.ImageIO; import javax.imageio.ImageReadParam; import javax.imageio.ImageReader; import javax.imageio.stream.ImageInputStream; import java.awt.*; import java.awt.image.BufferedImage; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.Iterator; public class Main { public static void cutImage(String src, String dest, int x, int y, int w, int h) throws IOException { Iterator iterator = ImageIO.getImageReadersByFormatName("jpg"); ImageReader reader = (ImageReader) iterator.next(); InputStream in = new FileInputStream(src); ImageInputStream iis = ImageIO.createImageInputStream(in); reader.setInput(iis, true);//from w w w . j av a 2 s. c o m ImageReadParam param = reader.getDefaultReadParam(); Rectangle rect = new Rectangle(x, y, w, h); param.setSourceRegion(rect); BufferedImage bi = reader.read(0, param); ImageIO.write(bi, "jpg", new File(dest)); } }