0

Hi guys

I want to take an image and cut it into blocks, then store each block in an array of bufferedimages.

I have tried many things

public void splitImage(int cols, int rows) 
  		{  
         int w = thePic.getWidth()/cols;  
         int h = thePic.getHeight()/rows;  
         int num = 0;  
         tileset = new BufferedImage[w*h];  
         for(int y = 0; y < rows; y++) {  
             for(int x = 0; x < cols; x++) {  
                 tileset[num] = new BufferedImage(w, h, thePic.getType());  
                 // Tell the graphics to draw only one block of the image  
                 Graphics2D g = tileset[num].createGraphics();  
                 g.drawImage(thePic, 0, 0, w, h, w*x, h*y, w*x+w, h*y+h, null);  
                 g.dispose();  
              num++;     
             }  
         }    
     }

This looks like it would work, but i tried testing it and it didn't. can anyone test it or point out the obvious flaw?

Thanks alot if you can

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by JamesCherrill
0

Don't know why that didn't work, but why not just use getSubimage(int x, int y, int w, int h) to create your array of sub-images directly?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.