Java Utililty Methods BufferedImage Split

List of utility methods to do BufferedImage Split

Description

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

Method

BufferedImage[]split(int w, int h, BufferedImage src)
split
int xs = src.getWidth() / w;
int ys = src.getHeight() / h;
BufferedImage[] result = new BufferedImage[xs * ys];
int i = 0;
for (int y = 0; y < ys; y++) {
    for (int x = 0; x < xs; x++) {
        result[i++] = src.getSubimage(x * w, y * h, w, h);
return result;
BufferedImage[]splitByWidth(BufferedImage img, int width)
Split the image into equally sized sub-images.
if (img.getWidth() > 0) {
    BufferedImage[] result = new BufferedImage[(img.getWidth() + width - 1) / width];
    int x = 0;
    for (int i = 0; i < result.length; i++) {
        int x2 = Math.min(x + width - 1, img.getWidth() - 1);
        result[i] = newSubimage(img, x, 0, x2 - x + 1, img.getHeight());
        x += width;
    return result;
return new BufferedImage[0];
BufferedImage[]splitImage(BufferedImage image, int row, int col)
Splits the image, uses the image width/height
return splitImage(image, image.getWidth(), image.getHeight(), row, col);
BufferedImage[]splitImage(BufferedImage image, int rows, int cols)
split Image
int chunks = rows * cols;
int chunkWidth = image.getWidth() / cols; 
int chunkHeight = image.getHeight() / rows;
int count = 0;
BufferedImage imgs[] = new BufferedImage[chunks]; 
for (int x = 0; x < rows; x++) {
    for (int y = 0; y < cols; y++) {
        int imageType = image.getType();
...
BufferedImage[]splitImage(BufferedImage img, int cols, int rows)
split Image
int w = img.getWidth() / cols;
int h = img.getHeight() / rows;
int num = 0;
BufferedImage imgs[] = new BufferedImage[w * h];
for (int y = 0; y < rows; y++) {
    for (int x = 0; x < cols; x++) {
        imgs[num] = new BufferedImage(w, h, img.getType());
        Graphics2D g = imgs[num].createGraphics();
...
BufferedImage[]splitImage(BufferedImage img, int rows, int cols)
split Image
if (img == null)
    throw new IllegalArgumentException("Image cannot be null!");
if (rows < 1 || cols < 1)
    throw new IllegalArgumentException("Rows and columns must be at least 1!");
BufferedImage[] bufs = new BufferedImage[rows * cols];
int width = img.getWidth() / cols;
int height = img.getHeight() / rows;
for (int i = 0; i < bufs.length; i++)
...
BufferedImage[]splitImage(final Image img, final int rows, final int cols)
Splits an image into a number of rows and columns
final int w = img.getWidth(null) / cols;
final int h = img.getHeight(null) / rows;
final int num = rows * cols;
int count = 0;
final BufferedImage[] imgs = new BufferedImage[num];
for (int x = 0; x < rows; x++) {
    for (int y = 0; y < cols; y++) {
        imgs[count] = new BufferedImage(w, h, Transparency.BITMASK);
...
BufferedImage[][]splitImage2D(BufferedImage img, int cols, int rows)
Load a image array.
w = img.getWidth() / cols;
h = img.getHeight() / rows;
imageType = img.getType();
if (imageType == 0)
    imageType = 5;
imgss = new BufferedImage[w][h];
for (int y = 0; y < rows; y++) {
    for (int x = 0; x < cols; x++) {
...
BufferedImage[]splitImageIntoTiles(final BufferedImage imageWithTiles, final int numberOfTilesAcross, final int numberOfTilesDown)
Creates subimages for each tile in the specified source image.
final int tileWidth = imageWithTiles.getWidth() / numberOfTilesAcross;
final int tileHeight = imageWithTiles.getHeight() / numberOfTilesDown;
final int totalNumberOfTiles = numberOfTilesDown * numberOfTilesAcross;
final BufferedImage[] tiles = new BufferedImage[totalNumberOfTiles];
for (int y = 0; y < numberOfTilesDown; y++) {
    for (int x = 0; x < numberOfTilesAcross; x++) {
        tiles[x + y * numberOfTilesAcross] = imageWithTiles.getSubimage(x * tileWidth, y * tileHeight,
                tileWidth, tileHeight);
...
BufferedImage[]splitVertically(BufferedImage top, int elements)
split Vertically
int currentY = 0;
int stepY = top.getHeight() / elements;
BufferedImage[] images = new BufferedImage[elements];
for (int i = 0; i < elements; i++) {
    images[i] = croppedCopy(top, 0, currentY, top.getWidth(), currentY + stepY);
    currentY += stepY;
return images;
...