Problem using ImageIO.read

后端 未结 3 1344
滥情空心
滥情空心 2021-02-13 19:45

Ok I have an Image that I\'m trying to read. Problem is that the Image.read(file) returns NULL.

File file = new File(\"C:\\\\images\\\\image1.jpg\");
if(file.exi         


        
相关标签:
3条回答
  • 2021-02-13 19:56

    Awesome, I had the same problem, wherein it was supporting 24 image formats in eclipse but was supporting only 12 image formats in command prompt with maven. Once I placed jai_imageio.jar in maven's test path, maven has begun to support 24 image formats as well.

    0 讨论(0)
  • 2021-02-13 19:57

    Ok since I switched laptops, I looked at my old laptop and found this JAR jai-imageio.jar in the jre/ext/lib (I know bad idea). I moved it to my project/lib and it worked! I guess this jai-imageio.jar contains additional image readers.

    0 讨论(0)
  • 2021-02-13 19:59

    From the Javadocs for ImageIO.read()

    Returns a BufferedImage as the result of decoding a supplied File with an ImageReader chosen automatically from among those currently registered. The File is wrapped in an ImageInputStream. If no registered ImageReader claims to be able to read the resulting stream, null is returned.

    Try creating an ImageInputStream, then pass that onto the ImageIO.read() method, instead of sending the file itself.

    0 讨论(0)
提交回复
热议问题