Reputation: 1509
I want to load a DICOM image using GDCM library in C#.
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.
Could someone please share any piece of code showing me how to achieve this ?
Upvotes: 2
Views: 2264
Reputation: 11977
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. Basically, when dealing with native buffers, WriteableBitmap
is the class you want to work with. 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.
Upvotes: 1