我想在下面的代碼中使用imageio在jpeg2000中轉換DICOM圖像,同樣的過程在oracle文檔中有解釋,但不起作用!我不明白我做錯了什麼。 Java高級映像I/O庫安裝在JRE中。使用imageio編寫jpeg2000的問題
使用:ImageIO.getReaderFormatNames()
和ImageIO.getWriterFormatNames()
可以驗證是否支持DICOM和JPEG2000!
沒有錯誤拋出,但寫入文件需要很長時間,並且輸出文件已損壞。
預先感謝您...
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();
}
}
即時可用的Java SE 7中支持的圖像格式似乎是JPEG,PNG,GIF和(W)BMP(調用'ImageIO.getReader/WriterFormatNames()'時獲得)。你能否解釋一下你是如何得出結論是_DICOM_和_JPEG2000_被支持的? –
@AndersGustafsson:我想提問者已經安裝了Java高級圖像I/O庫。這增加了讀寫TIFF和JPEG2000的能力,但我不確定DICOM。 –
@LukeWoodward感謝您的澄清。通常我會推薦使用DICOM工具包來促進這種類型的轉換。我認爲David Clunie的開源[Pixelmed](http://www.pixelmed.com/index.html#PixelMedJavaDICOMToolkit)Java DICOM Toolkit能夠以JPEG2000格式編寫圖像。 –