使用c#中的GDCM库加载DICOM映像,并转换为System.Windows.Control.Image

本文关键字:转换 System Windows Image Control 映像 中的 GDCM DICOM 加载 使用 | 更新日期: 2023-09-27 18:05:01

我想在c#中使用GDCM库加载DICOM图像。

我已经下载/安装了GDCM库,但我不知道如何使用GDCM读取DICOM图像并将其转换为可以在WPF应用程序中显示的格式。

有人可以分享任何一块代码告诉我如何实现这一点吗?

使用c#中的GDCM库加载DICOM映像,并转换为System.Windows.Control.Image

我不是在玩dicom,但出于好奇,我已经谷歌了如何将gdcm图像转换为Qt图像的样本(它是在c++中,但我希望c#端口提供相同的功能)你可能只是做他们正在做的事情,但有趣的部分是如何创建WPF图像而不是QTImage。基本上,当处理本机缓冲区时,WriteableBitmap是您想要使用的类。所以不是:

imageQt = new QImage(ubuffer, dimX, dimY, QImage::Format_RGB888);

你可以这样写:

int dimX;
int dimY;
byte* uBuffer; // Those fields are filled from code from this sample 
WriteableBitmap bmp = new WriteableBitmap(dimX, dimY, 96.0, 96.0, PixelFormats.Bgr24, null);
bmp.Lock();
bmp.CopyPixels(new Int32Rect(0, 0, dimX, dimY), uBuffer, uBuffer.Length, 
               uBuffer.Length / dimY);
bmp.Unlock();

WriteableBitmapBitmapSource,所以它可以像WPF中的任何其他图像一样使用。