1 package micropolisj.build_tool;
4 import java.awt.image.BufferedImage;
7 import javax.imageio.*;
8 import javax.swing.ImageIcon;
16 static final int DEST_COLUMNS = 16;
17 static final int TILE_SIZE = 16;
19 public static void main(String [] args)
22 File inputFile =
new File(args[0]);
23 File outputFile =
new File(args[1]);
26 Image srcImage =
new ImageIcon(inputFile.toString()).getImage();
27 int srcCols = srcImage.getWidth(null) / TILE_SIZE;
28 int srcRows = srcImage.getHeight(null) / TILE_SIZE;
29 int ntiles = srcRows * srcCols;
32 int destCols = DEST_COLUMNS;
33 int destRows = (ntiles + destCols-1) / destCols;
34 BufferedImage buf =
new BufferedImage(TILE_SIZE*DEST_COLUMNS,TILE_SIZE*destRows,BufferedImage.TYPE_INT_RGB);
35 Graphics2D gr = buf.createGraphics();
37 for (
int i = 0; i < ntiles; i++) {
39 int srcRow = i / srcCols;
40 int srcCol = i % srcCols;
42 int destRow = i / destCols;
43 int destCol = i % destCols;
47 destCol*TILE_SIZE, destRow*TILE_SIZE,
48 (destCol+1)*TILE_SIZE,(destRow+1)*TILE_SIZE,
49 srcCol*TILE_SIZE, srcRow*TILE_SIZE,
50 (srcCol+1)*TILE_SIZE, (srcRow+1)*TILE_SIZE,
54 ImageIO.write(buf,
"png", outputFile);