Java Utililty Methods Image Subimage

List of utility methods to do Image Subimage

Description

The list of methods to do Image Subimage are organized into topic(s).

Method

BufferedImagegetSubImage(Image image, int x, int y, int width, int height)
get Sub Image
if (x >= image.getWidth(null)) {
    throw new IllegalArgumentException(
            "The given x, " + x + ", must be less than the image width, " + width + ".");
if (y >= image.getHeight(null)) {
    throw new IllegalArgumentException(
            "The given y, " + y + ", must be less than the image height, " + height + ".");
if (x + width > image.getWidth(null)) {
    throw new IllegalArgumentException(
            "The given width must be less than or equal to the image width - x.");
if (y + height > image.getHeight(null)) {
    throw new IllegalArgumentException(
            "The given height must be less than or equal to the image height - y.");
BufferedImage subImage = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
Graphics graphics = subImage.getGraphics();
graphics.drawImage(image, 0, 0, subImage.getWidth(), subImage.getHeight(), x, y, x + width, y + height,
        null);
graphics.dispose();
return subImage;