结合PNG图像Java

时间:2015-04-25 17:49:21

标签: java bufferedimage

我正在尝试遍历png图像文件并将它们拼接在一起以形成一个图像。我没有使用for循环,只是将文件中的两个图像组合在一起工作。所以我假设它是循环不起作用。图像位于名为" images"的文件中。 我很感激您的意见!

        File file = new File("images");

    File [] moreFile = file.listFiles();
    String [] images = new String [moreFile.length];

    for(int i =0; i <images.length; i++)
        {images[i] = moreFile[i].getName();
        }

    int x = 0;
    int y = 0;
    BufferedImage result = new BufferedImage(
            controller.getSize().width*2, controller.getSize().height, //work these out
            BufferedImage.TYPE_INT_RGB);
    Graphics g = result.getGraphics();

    for(String image : images){
        System.out.println(image);

        File path = new File("images");
        try{ImageIO.read(new File(path, image));

        System.out.println("it definitely goes here");

        BufferedImage bi = new BufferedImage((2*510),(2*439),BufferedImage.TYPE_INT_ARGB);
        bi =ImageIO.read(new File(path, image));

        g.drawImage(bi, x, y, null);
        g.dispose();
    /// System.out.println(dafuck);
        x += bi.getWidth();

        if(x > result.getWidth()){
            x = 0;
            y += bi.getHeight();
        }
        }catch (Exception e) {
            System.out.println("is it an exception>?");

        }
    }

    try {
        ImageIO.write(result,"png",new File("results"));
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

0 个答案:

没有答案