获取ImageReader解析DICOM图像时出错 [英] Error getting ImageReader parsing DICOM image

查看:664
本文介绍了获取ImageReader解析DICOM图像时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试实现示例代码以从DicomObject获取图像:

I try to implement sample piece of code to get image from DicomObject:

import java.awt.image.BufferedImage;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Iterator;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;
import org.dcm4che2.data.DicomObject;
import org.dcm4che2.imageio.plugins.dcm.DicomImageReadParam;
import org.dcm4che2.io.DicomOutputStream;

....

public static BufferedImage getPixelDataAsBufferedImage(byte[] dicomData)
        throws IOException {
    ByteArrayInputStream bais = new ByteArrayInputStream(dicomData);
    BufferedImage buff = null;
    Iterator<ImageReader> iter = ImageIO.getImageReadersByFormatName("DICOM");
    ImageReader reader = (ImageReader) iter.next();
    DicomImageReadParam param = (DicomImageReadParam) reader.getDefaultReadParam();
    ImageInputStream iis = ImageIO.createImageInputStream(bais);
    reader.setInput(iis, false);
    buff = reader.read(0, param);
    iis.close();
    if (buff == null) {
        throw new IOException("Could not read Dicom file. Maybe pixel data is invalid.");
    }
    return buff;
}

ImageReader reader =(ImageReader)iter.next();我得到了:

When ImageReader reader = (ImageReader) iter.next(); I got:

Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/media/imageio/stream/StreamSegmentMapper
at org.dcm4che2.imageioimpl.plugins.dcm.DicomImageReaderSpi.createReaderInstance(DicomImageReaderSpi.java:146)
at javax.imageio.spi.ImageReaderSpi.createReaderInstance(ImageReaderSpi.java:320)
at javax.imageio.ImageIO$ImageReaderIterator.next(ImageIO.java:529)
at javax.imageio.ImageIO$ImageReaderIterator.next(ImageIO.java:513)
at dcm4.dcmTools.loadImage(dcmTools.java:61)
at dcm4.Dcm4.main(Dcm4.java:87)
Caused by: java.lang.ClassNotFoundException: com.sun.media.imageio.stream.StreamSegmentMapper
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 6 more

有人知道这是怎么回事吗???我在Windows7 64上使用JDK7 64。

Does anyone knows What is wrong??? I use JDK7 64 on Windows7 64

推荐答案

给定的异常表明您对Java Advanced Imaging(JAI)具有运行时依赖性。您需要标准JDK随附的其他JAR。

The given exception indicates that you have a runtime dependency on Java Advanced Imaging (JAI). You need additional JARs not provided with the standard JDK.

以下是 JAI JAI ImageIO Tools 的安装说明:

http://download.java.net/media/jai/builds/release/1_1_3/INSTALL.html#Windows

http://download.java.net/media/media/jai-imageio/builds/release /1.1/INSTALL-jai_imageio.html#Windows

您可以在此处下载安装程序:

You can download the installers here:

http://download.java.net/media/jai/builds/release / 1_1_3 /

http ://download.java.net/media/jai-imageio/builds/release/1.1/

一旦安装了JAI,您将需要在项目类路径中包含提取的JAR。

Once you install JAI, you will need to include the extracted JARs in your project classpath.

如果使用Maven,则可以在没有安装程序的情况下将JAI和JAI ImageIO Tools用于您的项目:

If using Maven, JAI and JAI ImageIO Tools can be used for your project without installers:

<dependency>
    <groupId>com.sun.media</groupId>
    <artifactId>jai_imageio</artifactId>
    <version>1.1</version>
</dependency>

这篇关于获取ImageReader解析DICOM图像时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆