简体   繁体   中英

Issue with DCIM to JPG converter

I have downloaded this library and I am running the code below:

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;
        }
}
}

and getting following exception

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)

Can anyone please help?

There's not too much information about dcm4che3 on the internet - especially not too many examples. I'm using this library in my application and was facing the same issue. I found that I need to load native libraries that are being distributed with Image IO library:

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

Please note they work only on Windows x64 (and other OS's).

One more thing, I'm keeping these libraries in my Jar and before I call System.load("libraryName") I need to retrieve it from the Jar and save in temporary file.

I guess, it depends some native library (eg .dll file). You can add code these libraries like below.

System.load("C:/pathMe/someLibrary.dll");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM