Question

I have many dicom (dcm) images that I want to display as thumbnails in my program. I can load it and draw in a separate window with ImageJ plugin:

try {
    FileInputStream fis = new FileInputStream(dcms);
    DICOM d = new DICOM(fis);
    d.run(dcms);
    d.setTitle(title);
    d.show();
    d.draw();
} catch (Exception e) {e.printStackTrace();}

}

But I want to be able to load it as a Image in a JavaFX button (as thumbnails) as I can do with pngs:

try{
    Image picture = new Image(getClass().getResourceAsStream(dcms));
    bt.setGraphic(new ImageView(picture));
}

I couldn't find any similar example on Google (most of the results lead to programs to convert the dicom to another thing through a program). But I don't want to convert and then display, I just want to display it.

Do you know if it's possible? Or will I have to convert it before loading the thumbnails?

EDIT : I know that I can save each picture somewhere e.g temp folder and then load it as a Image, but I still think that it's a unnecessary workaround. And I would like to avoid it if possible.

Was it helpful?

Solution

I found a way to use it:

            FileInputStream fis;
            try {
                fis = new FileInputStream(path);
                DICOM d = new DICOM(fis);
                d.run(path);
                Image picture = SwingFXUtils.toFXImage(d.getBufferedImage(), null);
                Button bt = new Button();
                bt.setGraphic(new ImageView(picture));
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

Posted because it might be useful for someone else.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top