Here you can find the source of cut(String srcImageFile, String result, int x, int y, int width, int height)
public static final void cut(String srcImageFile, String result, int x, int y, int width, int height)
//package com.java2s; //License from project: Apache License import java.awt.Graphics; import java.awt.Image; import java.awt.Toolkit; import java.awt.image.BufferedImage; import java.awt.image.CropImageFilter; import java.awt.image.FilteredImageSource; import java.awt.image.ImageFilter; import java.io.File; import javax.imageio.ImageIO; public class Main { public static final void cut(String srcImageFile, String result, int x, int y, int width, int height) { try {/* w ww .ja v a 2 s . c o m*/ BufferedImage bi = ImageIO.read(new File(srcImageFile)); int srcWidth = bi.getHeight(); int srcHeight = bi.getWidth(); if ((srcWidth > 0) && (srcHeight > 0)) { Image image = bi.getScaledInstance(srcWidth, srcHeight, 1); ImageFilter cropFilter = new CropImageFilter(x, y, width, height); Image img = Toolkit.getDefaultToolkit() .createImage(new FilteredImageSource(image.getSource(), cropFilter)); BufferedImage tag = new BufferedImage(width, height, 1); Graphics g = tag.getGraphics(); g.drawImage(img, 0, 0, width, height, null); g.dispose(); ImageIO.write(tag, "JPEG", new File(result)); } } catch (Exception e) { e.printStackTrace(); } } }