I'm trying to convert a DICOM image in jpeg2000 using imageio as in the below code, the same procedure is explained in oracle documentation, but doesn't work! I don't understand what I'm doing wrong. The Java Advanced Image I/O library is installed into the JRE.
Using: ImageIO.getReaderFormatNames()
and ImageIO.getWriterFormatNames()
it can be verified that DICOM and JPEG2000 are supported!
There are no errors thrown, but it takes too long to write the file, and the output file is corrupted.
Thank you in advance...
public void convert2JPEG(File sourceFileName) throws IOException{
Iterator<ImageReader> iter = ImageIO.getImageReadersByFormatName("DICOM");
ImageReader reader = iter.next();
if(reader == null) {
log.error("Could not locate any Readers for the DICOM format image.");
return;
}
File sourceFile = new File (sourceFileName);
ImageInputStream iis = ImageIO.createImageInputStream(sourceFile);
BufferedImage bi;
try{
bi = ImageIO.read(iis);
File outputFile = new File("outputFileName");
String format = "jpeg 2000";
ImageIO.write(bi, format, outputFile);
} catch(Exception e){
log.info("ERROR: " + e);
}finally {
iis.close();
}
}