使用Java和Jdeli读取jp2文件

时间:2018-07-11 18:34:23

标签: java

我想使用JDELi(https://files.idrsolutions.com/maven/site/jdeli/apidocs/com/idrsolutions/image/jpeg2000/Jpeg2000Decoder.html)在Java中读取jp2文件

    try{
        File f = new File("C:\\Users\\user\\Desktop\\b1.jp2"); //image file path



        byte[] bytesArray = new byte[(int) f.length()];

        FileInputStream fis = new FileInputStream(f);
        fis.read(bytesArray); //read file into bytes[]
        fis.close();

        Jpeg2000Decoder decoder = new Jpeg2000Decoder();
        BufferedImage decodedImage = decoder.read(bytesArray);
        ImageIO.write(decodedImage, "png", new FileImageOutputStream(new File("C:\\Users\\user\\Desktop\\test.png")));
    }catch(Exception e){
        System.out.println("Error: "+e);
    }

我在这里这一行得到一个空指针异常:decode.read(bytesArray);

这是我尝试加载的文件:http://www.share-online.biz/dl/HB52UPBP8ZO

,这里是错误:

Exception in thread "main" java.lang.NullPointerException
at com.idrsolutions.image.jpeg2000.TileParser.parseTile(TileParser.java:119)
at com.idrsolutions.image.jpeg2000.Jpeg2000Decoder.readCodeStream(Jpeg2000Decoder.java:445)
at com.idrsolutions.image.jpeg2000.Jpeg2000Decoder.decodeContiguousCodeStreamBoxes(Jpeg2000Decoder.java:297)
at com.idrsolutions.image.jpeg2000.Jpeg2000Decoder.read(Jpeg2000Decoder.java:61)
at test.testimagereader.main(testimagereader.java:36)

有人有主意吗?

谢谢

0 个答案:

没有答案