Kacper Lubisz
Kacper Lubisz

Reputation: 800

How to split an image into multiple smaller images

How can I split an Image object (java.awt.Image) into smaller images?

For example, splitting a 64*64px image into a sprite sheet of sixteen 16*16px images.

Upvotes: 6

Views: 8264

Answers (1)

obaqueiro
obaqueiro

Reputation: 982

See: http://rameshjavablog.blogspot.com/2012/04/sub-image-from-image-using-java.html

Using a function like:

image = createImage(new FilteredImageSource(image.getSource(),new CropImageFilter(13, 13, 143, 163)));

You are creating an image using the 'crop image filter').

Then it should just be a matter of iterating through the original image grabbing the different squares you want.

Upvotes: 4

Related Questions