Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

slicing up a very big jpg map image , 49000* 34300 pixel

Tags:

java

jai

tiling

i want to write a mapviewer, i must to work small tile of big map image file and there is need to tiling the big image, the problem now is to tiling big image to small tiles (250 * 250 pixel or like this size) so on, i used ImageMagic program to do it but there was problem now is any other programing method or application that do tiling? can i do it with JAI in java? how?

like image 854
sirvan Avatar asked Feb 28 '23 04:02

sirvan


1 Answers

Have you tried doing it in java yourself? I tried this with (WARNING, big image, can crash your browser, use "save as...") this image. Needed to run with extra memory though (-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")); 
            }
        }
    }
}
like image 67
dacwe Avatar answered Mar 08 '23 11:03

dacwe