Hi,
I'm training to use FO-DICOM, here is what I did :
DicomImage image = new DicomImage(filename);
byte[] byteArray = image.PixelData.GetFrame(0).Data;
Here are some of my image datas:
PhotometricInterpretation=MONOCHROME2
SamplePerPixel=1
BitsAllocated=16
BitsStored=12
HighBit=11
PixelRepresentation=0
NumberOfFrames=0
so the length of my byteArray is 524288, which seems to be good.
Now, (again, this is for training purpose, I know there are other ways to do it), I want to convert this byteArrays into a BitmapImage, or WritableImage, or whatever I could display on my WPF project using a Image.
I've been trying two methods:
- A "classic" way I found everywhere on internet:
BitmapImage bitmapImage;
using (MemoryStream ms = new MemoryStream(byteArray))
{
bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.StreamSource = ms;
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.EndInit(); // Here i get an exception
bitmapImage.Freeze();
}
with this I get a "System.NotSupportedException"
"Une exception non gérée du type 'System.NotSupportedException' s'est produite dans PresentationCore.dll
Informations supplémentaires : Impossible de trouver un composant d'image adapté pour terminer"
I guess in english it's something like : "Can't find a suitable image component to complete"
I guess this is not really a fo-ficom related question, but I hoped someone could tell me if i'm just using the "PixelData" the wrong way or something else...
- The second method was :
var width = 512;
var height = 512;
var dpiX = 96d;
var dpiY = 96d;
var pixelFormat = PixelFormats.Gray16;
var bytesPerPixel = 2;
var stride = bytesPerPixel * width;
var wbm = BitmapSource.Create(width, height, dpiX, dpiY, pixelFormat, null, tmp, stride);
This way, it's almost working ! The problem is that it's taking the image as a MONOCHROME1, and not as a MONOCHROME2 (I mean black & white are reverse), I don't really know how to fix this