我一直在使用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“”的定义,并且找不到接受类型为“”System.Windows.Forms.PictureBox“”的第一个参数的扩展方法“”Source“”(是否缺少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 Studio2010\Projects\ DICOMCA \DICOMCA\Form1.cs62 33DICOMCA
发布于 2013-08-02 17:18:58
正如错误所说,BitmapSource是一个System.Windows.Media.Imaging.BitmapSource图像,即它是一个WPF图像。
您的pictureBox1对象是一个System.Windows.Forms.PictureBox对象。
这两件事是不兼容的,您不能在Windows Forms PictureBox中显示WPF图像。
您需要将BitmapSource转换为常规的System.Drawing.Bitmap才能显示,但幸运的是,有多种方法可以做到这一点,尽管最佳选择有点取决于图像的像素格式。
How to convert BitmapSource to Bitmap
Is there a good way to convert between BitmapSource and Bitmap?
第二个链接上的答案是更快的方法。
https://stackoverflow.com/questions/17862457
复制相似问题