import java。awt。*;
import javax。swing。*;
class ImageTest extends JFrame {
public ImageTest() {
setSize(300,300);
setVisible(true);
}
public Image[] splitImage(String file, int rows, int cols) {
System。
out。println("Test");
Image t=new ImageIcon(file)。getImage();
Image[] result = new Image[rows * cols];
int w = t。getWidth(this)/cols;
int h = t。
getHeight(this)/rows;
try {
for(int i = 0;i
result[i] = this。createImage(w,h);
Graphics g = result[i]。getGraphics();
g。
translate((-i%cols)*w,(-i/cols)*h);
g。drawImage(t,0,0,this);
System。out。println("Test");
}
}
catch(Exception e) {}
return result;
}
}
class Test extends JFrame {
public Test() {
setSize(300,300);
setVisible(true);
}
public void paint(Graphics g) {
ImageTest tt = new ImageTest();
Image[] image = tt。
splitImage("1。gif",5,5);
g。drawImage(image[0],0,0,this);
}
public static void main(String [] args) {
new Test();
}
}
。
全部