I want to load a jpeg2000 image (.jp2) using Java JAI.
I'm already using an older JAI version which still supports the jpeg2000. I downloaded these images from scihub.copernicus.eu. These files are rather big (up to 100 MB). I tried several different approaches:
With java the standard way works like that:
public class Main { public static void main(String[] args) throws IOException { String path = "C:\\temp\\B2.jp2"; File inputFile = new File(path); Image result = ImageIO.read(inputFile); } }
The exception occurs with the following stacktrace:
Exception in thread "main" java.lang.RuntimeException: An uncaught runtime exception has occurred
at com.sun.media.imageioimpl.plugins.jpeg2000.J2KReadState.initializeRead(J2KReadState.java:708)
at com.sun.media.imageioimpl.plugins.jpeg2000.J2KReadState.<init>(J2KReadState.java:209)
at com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageReader.read(J2KImageReader.java:449)
at javax.imageio.ImageIO.read(ImageIO.java:1448)
at javax.imageio.ImageIO.read(ImageIO.java:1308)
at Main.main(Main.java:16)
Caused by: java.io.IOException: File too long.
at jj2000.j2k.fileformat.reader.FileFormatReader.readFileFormat(FileFormatReader.java:207)
at com.sun.media.imageioimpl.plugins.jpeg2000.J2KReadState.initializeRead(J2KReadState.java:418)
... 5 more
I expected to get a BufferedImage of the JPEP2000 File.
This is the default way of the JAI to load pictures.
public class Main { public static void main(String[] args) throws IOException { String path = "C:\\temp\\B2.jp2"; File inputFile = new File(path); RenderedOp image = JAI.create("fileload", inputFile.getPath()); Image result = image.getAsBufferedImage(); } }
However the variable image doesn't contain any data: The method getAsBufferedImage() throws the following exception:
Exception in thread "main" java.lang.RuntimeException: - Unable to render RenderedOp for this operation.
at javax.media.jai.RenderedOp.createInstance(RenderedOp.java:827)
at javax.media.jai.RenderedOp.createRendering(RenderedOp.java:867)
at javax.media.jai.RenderedOp.getColorModel(RenderedOp.java:2242)
at javax.media.jai.PlanarImage.getAsBufferedImage(PlanarImage.java:2498)
at javax.media.jai.PlanarImage.getAsBufferedImage(PlanarImage.java:2546)
at Main.main(Main.java:15)
Any other picture format works fine. What JAI libs are you using in order to load JPEG2000 files? Javax or the libs provided by github or any other? What does your code look like?