将gdcm_image转换为.NET位图失败

时间:2015-05-14 12:54:52

标签: c# gdcm

您正在尝试从DICOM文件中显示位图,但是当尝试从缓冲区创建位图时,我得到的参数对于Bitmap构造函数调用无效。我使用以下代码

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

0 个答案:

没有答案