此代码应在文件夹中查找图像,并将图像组合成 6000x6000 图像。它正在工作,但它真的很慢。我可以实现的任何优化?
File in = new File(args[1]);
File out = new File(args[2]);
in.mkdirs();
out.mkdirs();
if(out.exists())
{
out.delete();
}
if(!in.isDirectory())
{
Main.printUsage();
}
BufferedImage bout = new BufferedImage(6032, 6032, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = bout.createGraphics();
int count = 0;
long starttime = System.currentTimeMillis();
for(int i=0; i<=376; i++)
{
for(int k=0; k<=376; k++)
{
File cu = new File(in, (i-188)+"-"+(k-188)+".png");
if(cu.exists())
{
count++;
try {
g.drawImage(ImageIO.read(cu), 16*i, 16*k, null);
} catch (IOException e) {
e.printStackTrace();
}
Runtime.getRuntime().;
}
}
}
System.out.println("Processed "+count+" chunks in "+((System.currentTimeMillis()-starttime)/1000F)+" seconds");
g.dispose();
try {
ImageIO.write(bout, "png", out);
} catch (IOException e) {
e.printStackTrace();
}