简体   繁体   English

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

[英]Load DICOM image using GDCM library in C# and Convert to System.Windows.Control.Image

I want to load a DICOM image using GDCM library in C#. 我想在C#中使用GDCM库加载DICOM图像。

I have already downloaded/installed the GDCM library but I don't know how to read DICOM image using GDCM and convert it into a format which can be displayed in WPF application. 我已经下载/安装了GDCM库,但是我不知道如何使用GDCM读取DICOM图像并将其转换为可以在WPF应用程序中显示的格式。

Could someone please share any piece of code showing me how to achieve this ? 有人可以分享一些代码向我展示如何实现此目标吗?

I wasn't playing with dicom, but out of curiosity I've googled sample on how to convert gdcm image to Qt Image (it's in c++, but I hope that c# port offer same functionality) You can probably just do what they are doing, but interesting part is how to create WPF Image instead of QTImage. 我不是在玩dicom,但是出于好奇,我在google上搜索了如何将gdcm图像转换为Qt Image的示例(它使用c ++,但我希望c#端口提供相同的功能),您可能可以做他们正在做的事情,但有趣的部分是如何创建WPF图像而不是QTImage。 Basically, when dealing with native buffers, WriteableBitmap is the class you want to work with. 基本上,在处理本机缓冲区时, WriteableBitmap是您要使用的类。 So instead of: 所以代替:

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

You may use something like this: 您可以使用以下方式:

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();

WriteableBitmap is BitmapSource , so it can be used just like any other Image in WPF. WriteableBitmapBitmapSource ,因此可以像WPF中的任何其他Image一样使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM