Load Dicom image and display it - using ClearCanvas library

让人想犯罪 __ 提交于 2019-11-30 04:03:03

Okay, I figured it out.. There might be some more ways of achieving this, but this is what I did. Now I have a Wpf Image bound to a property which provides the bitmap data. The following is the property used to provide the Bitmap data.

public BitmapSource CurrentFrameData
{
    get
    {
        LocalSopDataSource _dicomDataSource = 
            new LocalSopDataSource(_dicomFilePath);
        var imageSop = new ImageSop(_dicomDataSource);

        IPresentationImage presentationImage = 
            PresentationImageFactory.Create(imageSop.Frames[CurrentFrame]);

        int width = imageSop.Frames[CurrentFrame].Columns;
        int height = imageSop.Frames[CurrentFrame].Rows;

        Bitmap bmp = presentationImage.DrawToBitmap(width, height);
        BitmapSource output = Imaging.CreateBitmapSourceFromHBitmap(
          bmp.GetHbitmap(),
          IntPtr.Zero,
          Int32Rect.Empty,
          BitmapSizeOptions.FromWidthAndHeight(width, height));

          return output;
    }
}

Note that this is a very straight forward solution. One might e.g. want to do stuff like preloading the pictures etc to avoid heavy load when scrolling multiframe images. But for the "howto display the image" question - this should answer it..

Martin Marconcini

Also check Steve, as he works in ClearCanvas. I’ve seen his response (and confirmation about this) in this StackOverflow question.

Ok, I've managed to show a DICOM image in a Picturebox using this code:

Here are the assemblies I used:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ClearCanvas.Common;
using ClearCanvas.Dicom;
using System.Windows.Media.Imaging;
using ClearCanvas.ImageViewer;
using ClearCanvas.ImageViewer.StudyManagement;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows;
using System.IO;

I also had to copy these dll into bin/debug:

BilinearInterpolation.dll (this one I could'nt reference it as assemblie so I just copied it into the bin/degug folder)

WindowsBase.dll (This one I was able to reference it as an assemblie)

Code (There's a button in my project that lets you select the dcm file and then show it in a picturebox)

Private void button2_Click(object sender, EventArgs e)
    {
        OpenFileDialog ofd = new OpenFileDialog();
        ofd.Filter = "DICOM Files(*.*)|*.*";
        if (ofd.ShowDialog() == DialogResult.OK)
        {
            if (ofd.FileName.Length > 0)
            {

                var imagen = new DicomFile(ofd.FileName); 

                LocalSopDataSource DatosImagen = new LocalSopDataSource(ofd.FileName); 

        ImageSop imageSop = new ImageSop(DatosImagen);

        IPresentationImage imagen_a_mostrar = PresentationImageFactory.Create(imageSop.Frames[1]); 

        int width = imageSop.Frames[1].Columns; 

        int height = imageSop.Frames[1].Rows; 

        Bitmap bmp = imagen_a_mostrar.DrawToBitmap(width, height); 

        PictureBox1.Image = bmp; 



            imageOpened = true;

            }
            ofd.Dispose();
        }
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!