Here you can find the source of crop(BufferedImage input, int x, int y, int width, int height)
public static BufferedImage crop(BufferedImage input, int x, int y, int width, int height)
//package com.java2s; /*/*from ww w .j ava2 s. c o m*/ * Copyright 2015 Laszlo Balazs-Csiki * * This file is part of Pixelitor. Pixelitor is free software: you * can redistribute it and/or modify it under the terms of the GNU * General Public License, version 3 as published by the Free * Software Foundation. * * Pixelitor is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Pixelitor. If not, see <http://www.gnu.org/licenses/>. */ import java.awt.Graphics2D; import java.awt.geom.AffineTransform; import java.awt.image.BufferedImage; public class Main { public static BufferedImage crop(BufferedImage input, int x, int y, int width, int height) { assert input != null; if (width <= 0) { throw new IllegalArgumentException("width = " + width); } if (height <= 0) { throw new IllegalArgumentException("height = " + height); } BufferedImage output = new BufferedImage(width, height, input.getType()); Graphics2D g = output.createGraphics(); AffineTransform t = AffineTransform.getTranslateInstance(-x, -y); g.transform(t); g.drawImage(input, null, 0, 0); g.dispose(); return output; } }