0

您好我正在尝试从 DICOM 文件中显示要显示的位图,但是当尝试从缓冲区创建位图时,我得到的 Parameter is not valid for the 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()));
        }
    }
}
4

0 回答 0