How To Split An Image Into Chunks - Java Imageio: Parallel Computing
How To Split An Image Into Chunks - Java Imageio: Parallel Computing
int num = 0;
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
finalImg.createGraphics().drawImage(buffImages[num],
chunkWidth * j, chunkHeight * i, null);
num++;
}
}
System.out.println("Image concatenated.....");
ImageIO.write(finalImg, "jpeg", new File("finalImg.jpg"));
receiving small chunks of an Image which is being manipulated parallely. In such scenarios, we need to concatenate those chunks
There is a pretty straight forward way to split an image using Java imageio package. Say you need to split following image into
several chunks (you should decide the no. of rows and columns needed).
Now I am going to split this image into 16 chunks (4 rows and 4 columns). I have shown the code snippet below.
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.*;
import java.awt.*;
int rows = 4; //You should decide the values for rows and cols
variables
int cols = 4;
int chunks = rows * cols;