Here you can find the source of crop(Image source, int x1, int y1, int x2, int y2)
public static Image crop(Image source, int x1, int y1, int x2, int y2)
//package com.java2s; //License from project: LGPL import java.awt.Graphics2D; import java.awt.Image; import java.awt.image.BufferedImage; import javax.swing.ImageIcon; public class Main { public static Image crop(Image source, int x1, int y1, int x2, int y2) { BufferedImage bi = toBufferedImage(source); BufferedImage img = bi.getSubimage(x1, y1, x2, y2); /*//w w w . j av a2s . co m JFrame frame = new JFrame(); Image cropped = frame.createImage(new FilteredImageSource(source.getSource(), new CropImageFilter(x1, y1, x2, y2))); frame.dispose(); */ return img; } public static BufferedImage toBufferedImage(Image img) { ImageIcon ii = new ImageIcon(img); img = ii.getImage(); BufferedImage bi = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB); Graphics2D g = bi.createGraphics(); g.drawImage(img, 0, 0, null); g.dispose(); return bi; } }