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

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

Description

Load a image array.

License

Apache License

Parameter

Parameter Description
img a parameter
cols a parameter
rows a parameter

Return

BufferedImage[]

Declaration

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

Method Source Code


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

import java.awt.AlphaComposite;

import java.awt.Graphics2D;

import java.awt.image.BufferedImage;

public class Main {
    private static BufferedImage imgss[][];
    private static Graphics2D g2;
    private static int w;
    private static int h;
    private static int imageType;

    /**/*  w  ww  .ja  v a  2  s .c om*/
     * Load a image array.
     * 
     * @param img
     * @param cols
     * @param rows
     * @return BufferedImage[]
     */
    public static BufferedImage[][] splitImage2D(BufferedImage img, int cols, int rows) {
        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++) {
                imgss[x][y] = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
                g2 = imgss[x][y].createGraphics();
                g2.setComposite(AlphaComposite.Src);
                g2.drawImage(img, 0, 0, w, h, w * x, h * y, w * x + w, h * y + h, null);
                g2.dispose();
            }
        }

        return imgss;
    }
}

Related

  1. splitImage(BufferedImage image, int row, int col)
  2. splitImage(BufferedImage image, int rows, int cols)
  3. splitImage(BufferedImage img, int cols, int rows)
  4. splitImage(BufferedImage img, int rows, int cols)
  5. splitImage(final Image img, final int rows, final int cols)
  6. splitImageIntoTiles(final BufferedImage imageWithTiles, final int numberOfTilesAcross, final int numberOfTilesDown)
  7. splitVertically(BufferedImage top, int elements)
  8. tileStretchPaint(Graphics g, JComponent comp, BufferedImage img, Insets ins)