如何在java中将jp2图像读入BufferedImage

时间:2014-12-27 17:01:45

标签: java image-processing jpeg2000

我想在java中将jp2图像读入BufferedImage。我安装了Java Advanced Imaging JAI。这是我的代码:

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

但是,我收到以下错误:

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)

我无法理解为什么JAI库无法读取jp2图像,尽管这个操作对于bmp图像是可行的..

任何提示请???

1 个答案:

答案 0 :(得分:0)

使用以下内容:

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


InputStream ism=new FileInputStream("/home/dhoha/Downloads/BreastCancer.jp2");
BufferedImage  buffImg  = ImageIO.read(ism);