使用ClearCanvas显示DICOM图像时出错

时间:2013-07-25 15:32:50

标签: c# image-processing dicom

我一直在使用ClearCanvas在C#中显示DICOM图像,开发人员Steve帮助我阅读图像的标签。但是,我已经坚持了将近两个星期的工作,并试图显示图像。我已经尝试并添加了史蒂夫帮助的代码,但我无法显示DICOM图像。也许我正在做的是不正确的,有人可以看看代码,并希望告诉我什么是错的或是他们的另一种显示方式。我一直试图让这个项目在C#中工作,希望能够转换为Visual Basic。我再次获得同样的错误。代码发布在下面。

enter
        string filename = @"C:\Users\Don jar\Pictures\Xray pics\fluro.dcm";
        DicomFile dicomFile = new DicomFile(filename);
        dicomFile.Load(DicomReadOptions.Default);
        foreach (DicomAttribute attribute in dicomFile.DataSet)
        {
            Console.WriteLine("Tag: {0}, Value: {1}", attribute.Tag.Name, attribute.ToString());
        }

        int bitsPerPixel = dicomFile.DataSet.GetAttribute(DicomTags.BitsStored).GetInt32(0, 0);
        int width = dicomFile.DataSet.GetAttribute(DicomTags.Columns).GetInt32(0, 0);
        int height = dicomFile.DataSet.GetAttribute(DicomTags.Rows).GetInt32(0, 0);
        int stride = width * 2;
        byte[] bitmapBuffer = (byte[])dicomFile.DataSet.GetAttribute(DicomTags.PixelData).Values;


        BitmapSource bitmapSource = BitmapImage.Create(width, height, 96, 96, System.Windows.Media.PixelFormats.Gray16, null, bitmapBuffer, stride);

        pictureBox1.Image = bitmapSource; code here

显示的错误位于最后一行 pictureBox1.Image = bitmapSource; 而错误是

错误1'System.Windows.Forms.PictureBox'不包含'Source'的定义,也没有扩展方法'Source'接受类型为'System.Windows.Forms.PictureBox'的第一个参数'(是您缺少using指令或程序集引用?)C:\ Users \ Don jar \ Documents \ Visual Studio 2010 \ Projects \ DICOMCA \ DICOMCA \ Form1.c

第二个错误是 错误2无法将类型'System.Windows.Media.Imaging.BitmapSource'隐式转换为'System.Drawing.Image'C:\ Users \ Don jar \ Documents \ Visual Studio 2010 \ Projects \ DICOMCA \ DICOMCA \ Form1.cs 62 33 DICOMCA

1 个答案:

答案 0 :(得分:0)

BitmapSource,如错误所示,是一个System.Windows.Media.Imaging.BitmapSource图像,即它是一个WPF图像。
你的pictureBox1对象是一个System.Windows.Forms.PictureBox对象 这两件事是不兼容的,您无法在Windows窗体PictureBox中显示WPF图像。

你需要将BitmapSource转换为常规的System.Drawing.Bitmap才能显示它,但幸运的是有多种方法可以做到这一点,尽管最好的选择类型取决于像素的格式。图像。
How to convert BitmapSource to Bitmap
Is there a good way to convert between BitmapSource and Bitmap?

第二个链接上的答案是更快的方法。