Java-如何使图像可读

时间:2017-11-04 18:55:17

标签: java image readable

我正在尝试使用png图像属性创建一个对象。我是一个代码来测试图像是否可读。我的代码告诉我图像不可读。有没有办法使图像可读或我需要找到新的图像?

    System.out.println(new File("king_of_hearts.png").getAbsolutePath()); // Try this to pinpoint your issue
            File king = new File("king_of_hearts.png");

            if(king.canRead()){ // Check if your file exists and is readable before you use it
                BufferedImage KingOfAxes = ImageIO.read(new File("king_of_hearts.png"));
            } else{
                throw new IOException(king.getName() + " is not readable!"); // Not readable -> Throw exception
            }
            System.out.println("King");

结果如下:

C:\Users\trevo\Desktop\Testcode\king_of_hearts.png
Exception in thread "main" java.io.IOException: king_of_hearts.png is not readable!
    at com.company.Main.main(Main.java:20)

Process finished with exit code 1

0 个答案:

没有答案