1

I want to read a jp2 image into BufferedImage in java. I installed the Java Advanced Imaging JAI. This is my code:

RenderedOp img = JAI.create("FileLoad",  "/home/dhoha/Downloads/BreastCancer.jp2");
  BufferedImage image =  img.getAsBufferedImage();

However, I get the following error:

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 testJai.test.main(test.java:19)

I cannot understand why the JAI library is not able to read the jp2 images although this operation is feasible with the bmp images..

Any hint please???

didowa
  • 106
  • 9

1 Answers1

-1

Use the following:

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;


InputStream ism=new FileInputStream("/home/dhoha/Downloads/BreastCancer.jp2");
BufferedImage  buffImg  = ImageIO.read(ism);
TiyebM
  • 2,684
  • 3
  • 40
  • 66