Here you can find the source of crop(BufferedImage src, int x, int y, int width, int height)
Parameter | Description |
---|---|
src | The input image |
x | Upper left point |
y | Upper left point |
width | of sub image |
height | of sub image |
public static BufferedImage crop(BufferedImage src, int x, int y, int width, int height)
//package com.java2s; /******************************************************************************* * Copyright (c) 2015 Christian Hensel// w ww . ja v a 2 s. c o m * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Christian Hensel - initial API and implementation *******************************************************************************/ import java.awt.Color; import java.awt.Graphics; import java.awt.image.BufferedImage; public class Main { /** * Helper methode to create a sub copy of the src input image. * Unfortunately BufferedImage.subImage - Methode returns the same data Array of input image -> changes in subimage would lead * to changes in inputImage. * * @param src * The input image * @param x * Upper left point * @param y * Upper left point * @param width * of sub image * @param height * of sub image * @return copy of input image */ public static BufferedImage crop(BufferedImage src, int x, int y, int width, int height) { BufferedImage returnImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics returnGraphics = returnImage.createGraphics(); for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { returnGraphics.setColor(new Color(src.getRGB(x + j, y + i))); returnGraphics.drawLine(j, i, j, i); } } return returnImage; } }