复制png图像,无一例外,但仍未复制。爪哇

我有这种方法来读取图像并复制它,但是令我困扰的是可以使用.jpg,.gif,.jpeg来实现,而不能使用.png。这是为什么?它不会引发异常,例如,如果我尝试使用.doc之类的东西,它将打印“读取完成”和“写入完成”,就像没有什么阻止它一样,但是目标文件夹中没有图像。

 public void copyImage(File f, String filename){ //Takes the file chosen and the name of it
        BufferedImage image = null;
        int width = 963;    //width of the image
        int height = 640;   //height of the image
        //read image
        try{
            image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
            image = ImageIO.read(f);
            System.out.println("Reading complete.");
        }catch(IOException e){
            System.out.println("Error: "+e);
        }

        //write image, here is the naming of the new image going, currently if same image often it is like image.jgp, image(1).jgp, image(1)(2).jpg......
        try{
            int imageNumer = 1; //For updating the number in the parenthesis based on how many with the same name in resources folder
            String imageName = filename;
            String outPath = "src/main/resources/images/"; //Path for saving, have special events folder now so if timeline guys are doing something they don't override copies
            while (folderHasImage(imageName)==true){ //Check if our folder has the imagename already if so, add (int) untill no more true
                int index = imageName.indexOf(".");            ;
                imageName = imageName.substring(0, index)+ "("+ imageNumer+")" + ".jpg";
                imageNumer++;
            }
            f = new File(outPath + imageName);  //output file path
            ImageIO.write(image, "jpg", f);
            System.out.println("Writing complete.");
        }catch(IOException e){
            System.out.println("Error: "+e);
        }
评论