简体   繁体   English

使用ClearCanvas显示DICOM图像时出错

[英]Error displaying DICOM image with ClearCanvas

I have been working in displaying a DICOM image in C# with ClearCanvas, the developer Steve aided me in reading in the tags for the image. 我一直在使用ClearCanvas在C#中显示DICOM图像,开发人员Steve帮助我读取了图像的标签。 However, I have been stuck for almost two weeks working on this project of and on trying to display the image. 但是,在这个项目以及尝试显示图像方面,我被困了将近两个星期。 I have tried and added code to what Steve helped with and yet I am unable to display the DICOM image. 我已经尝试过并将代码添加到Steve所提供的帮助中,但是仍然无法显示DICOM图像。 Maybe what i'm doing is incorrect, can someone take a look at the code and hopefully tell me what is wrong or is their an alternative way to display it. 也许我在做什么是不正确的,有人可以看一下代码并希望告诉我什么地方不对吗,或者是他们显示它的另一种方式。 I have been trying to get this project to work in C# with hopefully being able to convert to Visual basic. 我一直试图使该项目在C#中运行,希望能够转换为Visual Basic。 I am obtaining the same error over again. 我再次遇到相同的错误。 The code is posted below. 该代码发布在下面。

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

The error being displayed is on the last line pictureBox1.Image = bitmapSource; 显示的错误在最后一行pictureBox1.Image = bitmapSource;中。 and the the error is 错误是

Error 1 'System.Windows.Forms.PictureBox' does not contain a definition for 'Source' and no extension method 'Source' accepting a first argument of type 'System.Windows.Forms.PictureBox' could be found (are you missing a using directive or an assembly reference?) C:\\Users\\Don jar\\Documents\\Visual Studio 2010\\Projects\\DICOMCA\\DICOMCA\\Form1.c 错误1'System.Windows.Forms.PictureBox'不包含'Source'的定义,并且找不到扩展方法'Source'接受类型为'System.Windows.Forms.PictureBox'的第一个参数(您是否缺少使用指令还是程序集引用?)C:\\ Users \\ Don jar \\ Documents \\ Visual Studio 2010 \\ Projects \\ DICOMCA \\ DICOMCA \\ Form1.c

The second error is Error 2 Cannot implicitly convert type 'System.Windows.Media.Imaging.BitmapSource' to 'System.Drawing.Image' C:\\Users\\Don jar\\Documents\\Visual Studio 2010\\Projects\\DICOMCA\\DICOMCA\\Form1.cs 62 33 DICOMCA 第二个错误是错误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

BitmapSource is, as the error says, a System.Windows.Media.Imaging.BitmapSource image, ie it's a WPF image. 如错误所述,BitmapSource是一个System.Windows.Media.Imaging.BitmapSource图像,即它是WPF图像。
Your pictureBox1 object is a System.Windows.Forms.PictureBox object. 您的pictureBox1对象是System.Windows.Forms.PictureBox对象。
Those 2 things are incompatible, you cannot display a WPF image in a Windows Forms PictureBox. 这两件事是不兼容的,您不能在Windows Forms PictureBox中显示WPF图像。

You'll need to convert the BitmapSource to a regular System.Drawing.Bitmap in order to get it to display, but luckily there are multiple ways to do this, although the best option kind of depends on the pixel format of the image. 您需要将BitmapSource转换为常规的System.Drawing.Bitmap才能显示,但幸运的是,有多种方法可以做到这一点,尽管最好的选择取决于图像的像素格式。
How to convert BitmapSource to Bitmap 如何将BitmapSource转换为Bitmap
Is there a good way to convert between BitmapSource and Bitmap? 有没有一种在BitmapSource和Bitmap之间转换的好方法?

The answer on that second link is the faster way to do it though. 不过,第二个链接上的答案是更快的方法。

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

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