我已下载this library,我正在运行以下代码:
import java.awt.image.BufferedImage;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Iterator;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;
import org.dcm4che3.imageio.plugins.dcm.DicomImageReadParam;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
public class TestConverter {
public static void main(String... x) throws IOException, Exception{
TestConverter.dicomToJpeg("C:\\Users\\xxxxx\\Desktop\\SCOUT\\IM-0001-0001.dcm");
}
public static void dicomToJpeg(String args) throws IOException, Exception {
// TODO Auto-generated method stub
try
{
File myDicomFile = new File(args);
BufferedImage myJpegImage = null;
Iterator<ImageReader> iter = ImageIO.getImageReadersByFormatName("DICOM");
ImageReader reader = (ImageReader) iter.next();
DicomImageReadParam param = null;
try{
param = (DicomImageReadParam) reader.getDefaultReadParam();
}
catch (Exception e) {
e.printStackTrace();
}
ImageInputStream iis=ImageIO.createImageInputStream(myDicomFile);
reader.setInput(iis, false);
myJpegImage = reader.read(0, param);
iis.close();
if (myJpegImage == null) {
System.out.println("\nError: couldn't read dicom image!");
return;
}
File myJpegFile = new File("d:/demo.jpg");
OutputStream output = new BufferedOutputStream(new FileOutputStream(myJpegFile));
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(output);
encoder.encode(myJpegImage);
System.out.println("Image Create successufully");
output.close();
}
catch(IOException e){
System.out.println("\nError: couldn't read dicom image!"+ e.getMessage());
return;
}
}
}
并获得以下异常
Exception in thread "main" java.lang.UnsatisfiedLinkError: com.sun.medialib.codec.jp2k.Decoder.decode_init(Ljavax/imageio/stream/ImageInputStream;J)J
at com.sun.medialib.codec.jp2k.Decoder.decode_init(Native Method)
at com.sun.medialib.codec.jp2k.Decoder.<init>(Decoder.java:53)
at com.sun.media.imageioimpl.plugins.jpeg2000.J2KRenderedImageCodecLib.<init>(J2KRenderedImageCodecLib.java:158)
at com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageReaderCodecLib.read(J2KImageReaderCodecLib.java:367)
at org.dcm4che3.imageio.plugins.dcm.DicomImageReader.read(DicomImageReader.java:281)
at TestConverter.dicomToJpeg(TestConverter.java:43)
at TestConverter.main(TestConverter.java:22)
有人可以帮忙吗?
答案 0 :(得分:1)
在互联网上没有太多关于dcm4che3的信息 - 特别是没有太多的例子。我在我的应用程序中使用此库并遇到了同样的问题。我发现我需要加载与Image IO库一起分发的本机库:
请注意它们仅适用于Windows x64(以及其他操作系统)。
还有一件事,我将这些库保存在我的Jar中,然后调用 System.load(“libraryName”)我需要从Jar中检索它并保存在临时文件中。< / p>
答案 1 :(得分:0)
我猜,它取决于一些本地库(例如.dll文件)。您可以像下面这样添加代码库。
System.load("C:/pathMe/someLibrary.dll");