0

我一直在使用 ClearCanvas 在 C# 中显示 DICOM 图像,开发人员 Steve 帮助我阅读图像的标签。然而,我已经在这个项目上工作了将近两个星期,并试图显示图像。我已经尝试并在 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”的定义,并且找不到接受“System.Windows.Forms.PictureBox”类型的第一个参数的扩展方法“Source”(您是否缺少使用指令还是程序集引用?) 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 迪科马

4

1 回答 1

0

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

您需要将 BitmapSource 转换为常规 System.Drawing.Bitmap 以使其显示,但幸运的是,有多种方法可以做到这一点,尽管最佳选择取决于图像的像素格式。
如何将 BitmapSource 转换为 Bitmap
有没有在BitmapSource 和Bitmap 之间转换的好方法?

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

于 2013-08-02T09:18:58.433 回答