Here you can find the source of cutImage(File file, int x, int y, int width, int heigth)
public static void cutImage(File file, int x, int y, int width, int heigth) throws IOException
//package com.java2s; import java.awt.Rectangle; 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; import javax.imageio.ImageIO; import javax.imageio.ImageReadParam; import javax.imageio.ImageReader; import javax.imageio.stream.ImageInputStream; public class Main { public static void cutImage(File file, int x, int y, int width, int heigth) throws IOException { String fileName = file.getName(); String prefix = fileName.substring(fileName.lastIndexOf(".") + 1); Iterator<?> iterator = ImageIO.getImageReadersByFormatName(prefix); ImageReader reader = (ImageReader) iterator.next(); InputStream in = new FileInputStream(file); ImageInputStream iis = ImageIO.createImageInputStream(in); reader.setInput(iis, true);/* w w w . j a va 2s. com*/ ImageReadParam param = reader.getDefaultReadParam(); Rectangle rect = new Rectangle(x, y, width, heigth); param.setSourceRegion(rect); BufferedImage bi = reader.read(0, param); ImageIO.write(bi, prefix, file); iis.close(); in.close(); } }