Here you can find the source of splitImage2D(BufferedImage img, int cols, int rows)
Parameter | Description |
---|---|
img | a parameter |
cols | a parameter |
rows | a parameter |
public static BufferedImage[][] splitImage2D(BufferedImage img, int cols, int rows)
//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; } }