我正在尝试在 C# 中显示 DICOM 图像。感谢史蒂夫,我已经能够阅读 DICOM 文件。但是,想要显示 DICOM 图像,我有一个似乎试图显示图像的代码,但是它有一个错误。代码贴在下面。显示的错误如下。
错误 1
当前上下文中不存在名称“image1” C:\Users\Don jar\Documents\Visual Studio 2010\Projects\DICOMCA\DICOMCA\Form1.cs 52 13 DICOMCA
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);
image1.Source = bitmapSource;