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

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

Description

split Image

License

Apache License

Declaration

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

Method Source Code

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

import java.awt.Graphics2D;

import java.awt.image.BufferedImage;

public class Main {
    public static BufferedImage[] splitImage(BufferedImage img, int cols, int rows) {
        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());
                // Tell the graphics to draw only one block of the image  
                Graphics2D g = imgs[num].createGraphics();
                g.drawImage(img, 0, 0, w, h, w * x, h * y, w * x + w, h * y + h, null);
                g.dispose();/*from  www  .j  a  v  a2 s  .  com*/
                num++;
            }
        }
        return imgs;
    }
}

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 rows, int cols)
  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)