public BufferedImage[] splitImage(BufferedImage img, int cols, int rows) 
    {  
        int w = img.getWidth() / cols;  
        int h = img.getHeight() / rows; 
        int num = 0; 
        
        BufferedImage imgs[] = new BufferedImage[cols * rows];  
        
        for( int y = 0; y < rows; y++) 
        {  
            for(int x = 0; x < cols; x++) 
            {  
                imgs[num] = new BufferedImage(w, h, img.getType());   
                Graphics2D g = imgs[num].createGraphics();  
                g.drawImage(img, 0, 0, w, h, w*x, h*y, w*x+w, h*y+h, null);  
                g.dispose();  
                num++;  
            }  
        }  
        return imgs;