使用ClearCanvas显示DICOM图像时出错

本文关键字:出错 图像 DICOM ClearCanvas 显示 使用 | 更新日期: 2023-09-27 18:25:06

我一直在用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=位图源;错误为

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

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

使用ClearCanvas显示DICOM图像时出错

BitmapSource是一个System.Windows.Media.Imaging.BitmapSource映像,也就是说它是一个WPF映像
您的pictureBox1对象是System.Windows.Forms.PictureBox对象
这两件事是不兼容的,你不能在Windows窗体PictureBox中显示WPF图像。

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

第二个环节的答案是更快的方法。