Java Utililty Methods BufferedImage Crop

List of utility methods to do BufferedImage Crop

Description

The list of methods to do BufferedImage Crop are organized into topic(s).

Method

ListcropToBeSameSize(BufferedImage image1, BufferedImage image2)
Resize images to be same size.
if (imagesSameSize(image1, image2)) {
    return Arrays.asList(image1, image2);
int minHeight = Math.min(image1.getHeight(), image2.getHeight());
int minWidth = Math.min(image1.getWidth(), image2.getWidth());
BufferedImage cropped1 = cropImage(image1, minWidth, minHeight);
BufferedImage cropped2 = cropImage(image2, minWidth, minHeight);
return Arrays.asList(cropped1, cropped2);
...
ListdivideImage(BufferedImage bi, int rows, int cols, int width, int height)
divide Image
int x, y;
List<BufferedImage> imagenes = new ArrayList<>();
for (int i = 0; i < rows; i++) {
    for (int j = 0; j < cols; j++) {
        x = j * width;
        y = i * height;
        imagenes.add(bi.getSubimage(x, y, width, height));
return imagenes;
BufferedImagedoCrop(BufferedImage bufferedImage, int cropX, int cropY, int width, int height)
do Crop
return bufferedImage.getSubimage(cropX, cropY, width, height);
JButtondrawCropped(JPanel contentPane, ActionListener listener, BufferedImage img, int type, int sx1, int sy1, int sx2, int sy2, int x, int y, int scale)
draw Cropped
return drawCropped(contentPane, listener, img, type, sx1, sy1, sx2, sy2, x, y, scale, false);
voidImageCrop(String sourcePath, String descPath, int cropX, int cropY, int width, int height)
crop image with certain parameters
BufferedImage bufferedImage = readImageFile(sourcePath);
bufferedImage = doCrop(bufferedImage, cropX, cropY, width, height);
saveImageFile(bufferedImage, getImageSuffix(sourcePath), descPath);
BufferedImageimgUtilFastCrop(BufferedImage src, int x, int y, int width, int height)
Quickly crops an image from its source.
if (src == null)
    return null;
if (x == 0 && y == 0 && width == src.getWidth() && height == src.getHeight())
    return imgUtilFastCopy(src);
else {
    BufferedImage b = new BufferedImage(width, height, src.getType());
    Graphics g = b.getGraphics();
    g.drawImage(src, -x, -y, null);
...
BufferedImagezealousSubsCrop(BufferedImage img)
zealous Subs Crop
int initialHeight = img.getHeight();
int initialWidth = img.getWidth();
int newHeight = initialHeight / 2;
int newWidth = initialWidth / 2;
return img.getSubimage(newWidth / 2, newHeight, newWidth, newHeight);