Skip to content

Instantly share code, notes, and snippets.

@dedunumax
Created May 2, 2014 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dedunumax/50ae2cf488f55d05e945 to your computer and use it in GitHub Desktop.
Save dedunumax/50ae2cf488f55d05e945 to your computer and use it in GitHub Desktop.
This program will cut a single image into several image files
package org.dedunumax.imagecutter;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class ImageCutter {
public static void main(String[] args) throws IOException {
File path = new File("/home/images/");
int margin = 38, padding = 18, dimension = 640, numberOfImages = 23;
BufferedImage image = ImageIO.read(new File(path, "full.png"));
for (int i = 0; i < numberOfImages; i++) {
System.out.println("Index : " + i + " Y: "
+ ((dimension + padding) * i) + margin);
BufferedImage temp = image.getSubimage(0,
((dimension + padding) * i) + margin, dimension, dimension);
ImageIO.write(temp, "PNG", new File(path, "Figure_" + (i + 1)
+ ".png"));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment