Java BufferedImage Split splitImage(BufferedImage img, int rows, int cols)

Here you can find the source of splitImage(BufferedImage img, int rows, int cols)

Description

split Image

License

Apache License

Declaration

public static BufferedImage[] splitImage(BufferedImage img, int rows, int cols) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.awt.image.BufferedImage;

public class Main {
    public static BufferedImage[] splitImage(BufferedImage img, int rows, int cols) {
        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++)
            bufs[i] = img.getSubimage(i % cols * width, i / cols * height, width, height);
        return bufs;
    }//  w ww  .  j a va 2 s  .c o  m
}

Related

  1. split(int w, int h, BufferedImage src)
  2. splitByWidth(BufferedImage img, int width)
  3. splitImage(BufferedImage image, int row, int col)
  4. splitImage(BufferedImage image, int rows, int cols)
  5. splitImage(BufferedImage img, int cols, int rows)
  6. splitImage(final Image img, final int rows, final int cols)
  7. splitImage2D(BufferedImage img, int cols, int rows)
  8. splitImageIntoTiles(final BufferedImage imageWithTiles, final int numberOfTilesAcross, final int numberOfTilesDown)
  9. splitVertically(BufferedImage top, int elements)