Java BufferedImage Operation chunk(BufferedImage image)

Here you can find the source of chunk(BufferedImage image)

Description

chunk

License

Open Source License

Declaration

public static void chunk(BufferedImage image) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.*;
import java.awt.*;

public class Main {
    private static int rows = 2;
    private static int cols = 2;

    public static void chunk(BufferedImage image) throws IOException {

        int chunks = rows * cols;

        int chunkWidth = image.getWidth() / cols; // determines the chunk width and height  
        int chunkHeight = image.getHeight() / rows;
        int count = 0;
        BufferedImage imgs[] = new BufferedImage[chunks]; //Image array to hold image chunks  
        for (int x = 0; x < rows; x++) {
            for (int y = 0; y < cols; y++) {
                //Initialize the image array with image chunks  
                imgs[count] = new BufferedImage(chunkWidth, chunkHeight,
                        image.getType());

                // draws the image chunk  
                Graphics2D gr = imgs[count++].createGraphics();
                gr.drawImage(image, 0, 0, chunkWidth, chunkHeight,
                        chunkWidth * y, chunkHeight * x, chunkWidth * y
                                + chunkWidth,
                        chunkHeight * x + chunkHeight, null);
                gr.dispose();/*from  w  w  w . java  2  s.c  o m*/
            }
        }
        System.out.println("Splitting done");

        //writing mini images into image files  
        for (int i = 0; i < imgs.length; i++) {
            ImageIO.write(imgs[i], "jpg", new File("tmp/img" + i + ".jpg"));
        }
        System.out.println("Mini images created");
    }
}

Related

  1. changeImageToArray(BufferedImage bufferedImage)
  2. checkIfManyColors(BufferedImage image)
  3. checkImageMatch(BufferedImage img1, String imgName1, BufferedImage img2, String imgName2)
  4. checkImageType(BufferedImage img, String name)
  5. checkRadius(final BufferedImage src, final int x, final int y, final int opaqueLimit, final int radius)
  6. circularize(BufferedImage image)
  7. cleanBinaryImage(BufferedImage image)
  8. compose(BufferedImage image, BufferedImage mask)
  9. composite(BufferedImage bg, BufferedImage fg)