简体   繁体   English

在JavaFX按钮中显示dicom

[英]Display dicom in JavaFX button

I have many dicom (dcm) images that I want to display as thumbnails in my program. 我有许多要以缩略图形式显示在程序中的dicom(dcm)图像。 I can load it and draw in a separate window with ImageJ plugin: 我可以加载它并使用ImageJ插件在单独的窗口中绘制:

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: 但是我希望能够像使用png一样将其作为图像加载到JavaFX按钮中(作为缩略图):

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). 我在Google上找不到任何类似的示例(大多数结果导致程序通过程序将dicom转换为另一种东西)。 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 eg temp folder and then load it as a Image, but I still think that it's a unnecessary workaround . 编辑:我知道我可以将每张图片保存在某个位置,例如temp文件夹,然后将其加载为Image,但是我仍然认为这是不必要的解决方法 And I would like to avoid it if possible. 我想避免这种情况。

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. 发布,因为它可能对其他人有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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