问题描述
这是一个非常狭隘和具体的问题,但我知道有其他人在那里使用这个,所以我会保持双手交叉,希望你们中的任何人都可以提出这个问题。
This is a very narrow and specific question, but I know there are someone else out there using this, so I'll keep my fingers crossed and hope anyone of you pics this question up.
我正在开发一个WPF应用程序,其中一部分是Dicom查看器。我们想使用第三方组件来处理Dicom的东西,而ClearCanvas是我们迄今为止最好的印象。我们能够加载Dicom文件并获取属性,但是我们在将图像数据放在Image控件的Source属性上以显示它时遇到问题。任何有关如何实现这一目标的提示?
I'm working on a WPF application where one part of it is a Dicom viewer. We'd like to use a 3rd party component to handle the Dicom stuff, and ClearCanvas is the one we've got the best impression of this far. We're able to load a Dicom file and fetch the attributes, but we're having problems putting the image data on the Source property of an Image control to show it. Anyone with hints on how to make this happen?
以下是我用于提取图像数据的代码:
Here's the code I use for extracting the image data:
var file = new DicomFile(dicomFilePath);
var patientName = file.DataSet.GetAttribute(DicomTags.PatientsName);
var imageData = file.DataSet.GetAttribute(DicomTags.PixelData);
还尝试使用ImageViewer库,但它仍然是相同的数据..
Have also tried using the ImageViewer library, but it is still the same data..
var localSopDataSource = new LocalSopDataSource(new DicomFile(dicomFilePath));
var patientName = localSopDataSource.File.DataSet.GetAttribute(DicomTags.PatientsName);
var imageData = localSopDataSource.File.DataSet.GetAttribute(DicomTags.PixelData);
推荐答案
好的,我想出来了......可能有实现这一目标的更多方法,但这就是我所做的。现在我有一个绑定到提供位图数据的属性的Wpf图像。以下是用于提供位图数据的属性。
Okay, I figured it out.. There might be some more ways of achieving this, but this is what I did. Now I have a Wpf Image bound to a property which provides the bitmap data. The following is the property used to provide the Bitmap data.
public BitmapSource CurrentFrameData
{
get
{
LocalSopDataSource _dicomDataSource =
new LocalSopDataSource(_dicomFilePath);
var imageSop = new ImageSop(_dicomDataSource);
IPresentationImage presentationImage =
PresentationImageFactory.Create(imageSop.Frames[CurrentFrame]);
int width = imageSop.Frames[CurrentFrame].Columns;
int height = imageSop.Frames[CurrentFrame].Rows;
Bitmap bmp = presentationImage.DrawToBitmap(width, height);
BitmapSource output = Imaging.CreateBitmapSourceFromHBitmap(
bmp.GetHbitmap(),
IntPtr.Zero,
Int32Rect.Empty,
BitmapSizeOptions.FromWidthAndHeight(width, height));
return output;
}
}
请注意,这是一个非常直接的解决方案。一个可能是想要做一些事情,如预加载图片等,以避免在滚动多帧图像时的重负荷。但对于如何显示图像的问题 - 这应该回答它..
Note that this is a very straight forward solution. One might e.g. want to do stuff like preloading the pictures etc to avoid heavy load when scrolling multiframe images. But for the "howto display the image" question - this should answer it..
这篇关于加载Dicom图像并显示它 - 使用ClearCanvas库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!