我想写一个 map 查看器,我必须处理大 map 图像文件的小图 block 并且需要平铺大图像,现在的问题是将大图像平铺成小图 block (250 * 250 像素或像这样尺寸) 等等,我用 ImageMagic 程序来做,但有问题 现在有任何其他编程方法或应用程序可以平铺吗? 我可以用 Java 中的 JAI 来做吗?怎么办?
最佳答案
您是否尝试过自己用 Java 来实现?我试过这个(警告,大图,会使你的浏览器崩溃,使用“另存为...”)this image .虽然需要额外的内存来运行 (-Xmx400M
)。
public class ImageTile {
public static void main(String[] args) throws IOException {
Dimension tileDim = new Dimension(250, 250);
BufferedImage image = ImageIO.read(new File(args[0]));
Dimension imageDim = new Dimension(image.getWidth(), image.getHeight());
for(int y = 0; y < imageDim.height; y += tileDim.height) {
for(int x = 0; x < imageDim.width; x += tileDim.width) {
int w = Math.min(x + tileDim.width, imageDim.width) - x;
int h = Math.min(y + tileDim.height, imageDim.height) - y;
BufferedImage tile = image.getSubimage(x, y, w, h);
ImageIO.write(tile, "JPG", new File("tile-"+x+"-"+y+".jpg"));
}
}
}
}
关于java - 切片一个非常大的 jpg map 图像,49000* 34300 像素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2649048/