It is easier to split image since JDK 1.4 introducing package javax.imageio.* .

class javax.imageio.ImageIO contains many static method dealing with image processing and using it, image manipulation became easy compared to former JDK.

original image to be splitted


It shows that above one image is splitted into 9 ones

an image splitted into nine ones.


Here is simple class ImagePanel extending javax.swing.JPanel where splitted images are managed and drawn whenever repaint() is called.

Method BufferedImage.getSubImage(int, int, int, int) has 4 properties specifying the region of each sub-image and each one is managed by class "ImageNode" which is a private inner class defined in the class ImagePanel.


When using mehtod "getSubImage", be aware of the target of the coordinats.

Yellow is an original image and orange sub image



offset X and offset Y should be calculated within the original image itself, neighter parent container containing it nor screen.

Now move to the drawing point.

Because ImagePanel is inherited from JPanel, method paintComponent is appropriate for drawing each of images. When repaint() is called, paintComponent is always invoked automatically.

Method Graphics.translate(..) is frequently used to simplify an puzzling and complicating drawing. It moves current coordinate values from the Graphics to the specifying new values and then ImageNode drawing each image doesn't care about the whole coordinates values.

With Graphics.translate(..), ImageNode can concentrate on its own drawing as if it is the only one drawing image on the canvas.

Whenever calling Graphics.translate(x, y), always call translate(-x, -y) once again with (-x, -y) so that following jobs doesn't have troubles.

Using ImagePanel is simple like JPanel.
ImagePanel divide an image into 5 rows and 3 columns sub ones.

below is constructor of ImagePanel
Posted by yeori
,