0

Hi am trying to get bitmap to display from DICOM file , but when try to create bitmap from the buffer I get Parameter is not valid for the Bitmap constructor call. I use the following code

gdcm.ImageReader reader = new gdcm.ImageReader();
reader.SetFileName(_dicomFilePath);
if (reader.Read())
{
    var image = reader.GetImage();
    if (image != null)
    {
        byte[] imageByteArray = new byte[image.GetBufferLength()];
        if (image.GetBuffer(imageByteArray))
        {
            MemoryStream stream = new MemoryStream();
            stream.Write(imageByteArray, 0, imageByteArray.Length);
            stream.Seek(0, SeekOrigin.Begin);
            Bitmap bmp = new Bitmap(stream);
            CurrentFrameDataGDCM = Imaging.CreateBitmapSourceFromHBitmap(
                    bmp.GetHbitmap(),
                    IntPtr.Zero,
                    Int32Rect.Empty,
                    BitmapSizeOptions.FromWidthAndHeight((int)image.GetRows(), (int)image.GetColumns()));
        }
    }
}
Steve Mitcham
  • 5,268
  • 1
  • 28
  • 56
AMH
  • 6,363
  • 27
  • 84
  • 135
  • You need to add the specific error message along with the stack trace so we know which parameter is having the issue. – Steve Mitcham May 14 '15 at 13:27
  • @SteveMitcham just get error from at System.Drawing.Bitmap..ctor(Stream stream) – AMH May 14 '15 at 13:35
  • What is the type of the return value for `reader.GetImage()`? I suspect that it is not the same binary format as a .NET `Bitmap` so it can be deserialized into the Bitmap object. – Steve Mitcham May 14 '15 at 13:39
  • yes not the same that's why I get the buffer from it to display it's gdcm_image – AMH May 14 '15 at 13:45
  • 1
    Right, the Stream constructor is only useful for a stream that is in a supported format. Unless that image object has a direct conversion to a .NET Bitmap in the API somewhere, you'll have to use the empty constructor and roll your own converter. I'm not familiar with the library that you are using. Here's the link to the types of bitmap formats that are directly supported. https://msdn.microsoft.com/en-us/library/at62haz6(v=vs.110).aspx – Steve Mitcham May 14 '15 at 13:55
  • 1
    did you figure something out @AMH , I have the same problem – mahmoud nezar sarhan Oct 14 '17 at 09:28

0 Answers0