Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package tool;
- import java.awt.image.BufferedImage;
- import java.io.File;
- import java.io.IOException;
- import javax.imageio.ImageIO;
- /**
- *
- * @author Vipar
- */
- public class TileSeparator {
- private BufferedImage image;
- private int tileSize;
- private String destinationFolder;
- public TileSeparator(BufferedImage image, int tileSize,
- String destinationFolder) {
- this.image = image;
- this.tileSize = tileSize;
- this.destinationFolder = destinationFolder;
- }
- public void generateTiles() throws IOException {
- int counter = 0;
- int width = image.getWidth() / tileSize;
- int height = image.getHeight() / tileSize;
- int x = 0;
- int y = 0;
- BufferedImage tile;
- File outputFile;
- for(int i = 0; i < height; i++) {
- for(int j = 0; j < width; j++) {
- tile = image.getSubimage(x, y, tileSize/2, tileSize/2);
- x += tileSize;
- outputFile = new File(destinationFolder + counter + ".png");
- ImageIO.write(tile,"png",outputFile);
- counter++;
- }
- y += tileSize;
- x = 0;
- }
- }
- }
Add Comment
Please, Sign In to add comment