Here you can find the source of getSubimage(BufferedImage image, int x, int y, int width, int height)
Parameter | Description |
---|---|
IllegalArgumentException | an exception |
public static BufferedImage getSubimage(BufferedImage image, int x, int y, int width, int height)
//package com.java2s; //License from project: Open Source License import java.awt.Rectangle; import java.awt.image.BufferedImage; public class Main { /**/*from ww w.j a va 2 s. c o m*/ * @throws IllegalArgumentException */ public static BufferedImage getSubimage(BufferedImage image, int x, int y, int width, int height) { // Validate arguments if ((x < 0) || (width < 0) || (x + width > image.getWidth()) || (y < 0) || (height < 0) || (y + height > image.getHeight())) throw new IllegalArgumentException(); // Create a new image from a region of the input image BufferedImage subimage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); int[] rgbBuffer = new int[width * height]; image.getRGB(x, y, width, height, rgbBuffer, 0, width); subimage.setRGB(0, 0, width, height, rgbBuffer, 0, width); return subimage; } /** * @throws IllegalArgumentException */ public static BufferedImage getSubimage(BufferedImage image, Rectangle rect) { return getSubimage(image, rect.x, rect.y, rect.width, rect.height); } }