gpt4 book ai didi

java - DCIM 到 JPG 转换器的问题

转载 作者:搜寻专家 更新时间:2023-10-31 20:34:25 29 4
gpt4 key购买 nike

我已经下载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)

有人可以帮忙吗?

最佳答案

互联网上没有太多关于 dcm4che3 的信息——尤其是没有太多例子。我在我的应用程序中使用这个库并且面临同样的问题。我发现我需要加载与 Image IO 库一起分发的 native 库:

  • clib_jiio.dll
  • clib_jiio_sse2.dll
  • clib_jiio_util.dll

请注意它们仅适用于 Windows x64(和其他操作系统)。

还有一件事,我将这些库保存在我的 Jar 中,在我调用 System.load("libraryName") 之前,我需要从 Jar 中检索它并保存在临时文件中。

关于java - DCIM 到 JPG 转换器的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22468318/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com