Here you can find the source of newSubimage(BufferedImage src, int x, int y, int w, int h)
Parameter | Description |
---|---|
src | the source image. |
x | the x coordinate |
y | the y coordinate |
w | the width |
h | the height |
public static BufferedImage newSubimage(BufferedImage src, int x, int y, int w, int h)
//package com.java2s; /*//from ww w . j av a 2 s. c o m * Copyright 2008-2014, David Karnok * The file is part of the Open Imperium Galactica project. * * The code should be distributed under the LGPL license. * See http://www.gnu.org/licenses/lgpl.html for details. */ import java.awt.image.BufferedImage; public class Main { /** * Returns an independent subimage of the given main image. copying data from the original image. * @param src the source image. * @param x the x coordinate * @param y the y coordinate * @param w the width * @param h the height * @return the extracted sub-image */ public static BufferedImage newSubimage(BufferedImage src, int x, int y, int w, int h) { BufferedImage bimg = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); int[] tmp = new int[w * h]; src.getRGB(x, y, w, h, tmp, 0, w); bimg.setRGB(0, 0, w, h, tmp, 0, w); return bimg; } }