Java BufferedImage Split splitImage(BufferedImage image, int row, int col)

Here you can find the source of splitImage(BufferedImage image, int row, int col)

Description

Splits the image, uses the image width/height

License

Open Source License

Parameter

Parameter Description
image a parameter
row a parameter
col a parameter

Declaration

public static BufferedImage[] splitImage(BufferedImage image, int row, int col) 

Method Source Code

//package com.java2s;
/*/*from w ww.  ja  v a2s.com*/
 *    leola-live 
 *  see license.txt
 */

import java.awt.image.BufferedImage;

public class Main {
    /**
     * Splits the image, uses the image width/height 
     * @param image
     * @param row
     * @param col
     * @return
     */
    public static BufferedImage[] splitImage(BufferedImage image, int row, int col) {
        return splitImage(image, image.getWidth(), image.getHeight(), row, col);
    }

    /**
     * Splits the image 
     * @param image
     * @param width
     * @param height
     * @param row
     * @param col
     * @return
     */
    public static BufferedImage[] splitImage(BufferedImage image, int width, int height, int row, int col) {
        int total = col * row; // total returned images
        int frame = 0; // frame counter

        int w = width / col;
        int h = height / row;

        BufferedImage[] images = new BufferedImage[total];

        for (int j = 0; j < row; j++) {
            for (int i = 0; i < col; i++) {
                BufferedImage tmp = image.getSubimage(i * w, j * h, w, h);
                images[frame++] = tmp;
            }
        }

        return images;
    }
}

Related

  1. split(int w, int h, BufferedImage src)
  2. splitByWidth(BufferedImage img, int width)
  3. splitImage(BufferedImage image, int rows, int cols)
  4. splitImage(BufferedImage img, int cols, int rows)
  5. splitImage(BufferedImage img, int rows, int cols)
  6. splitImage(final Image img, final int rows, final int cols)