我最近开始评估 fo-dicom 作为未来项目可能的 DICOM 库,所以我对它很陌生。
我构建了一个基本的 C# Windows Forms 应用程序,它只读取一个 DICOM 文件,将其转换为 aSystem.Drawing.Bitmap
并显示在 a 中PictureBox
:
public partial class TestFoDicomForm : Form
{
public TestFoDicomForm()
{
InitializeComponent();
DicomImage di = new DicomImage("Image_01.dcm");
Bitmap bmp = di.RenderImage().AsBitmap();
this._pbDicomImage.Image = bmp;
}
}
这段代码起作用,但如果我开始调整表单大小,异常来得比以后更早:
System.ArgumentException:参数无效。
在 System.Drawing.Image.get_RawFormat()
在 System.Drawing.Graphics.DrawImage(Image image, Int32 x, Int32 y, Int32 width, Int32 height)
在 System.Drawing.Graphics.DrawImage(Image image, Rectangle rect)
在System.Windows.Forms.PictureBox.OnPaint(PaintEventArgs pe)
在 System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
在 System.Windows.Forms.Control.WmPaint(Message& m)
在 System.Windows.Forms .Control.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.Callback (IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
异常实际上发生在Main()
Application.Run(new TestFoDicomForm());
但我无法添加一个功能try/catch
来调查有效发生的事情。
我通过 NuGet 添加了对 fo-dicom 3.0.2 的引用(项目的目标框架是 4.6.1)。环境:Windows 10 专业版,VS 2017。
有趣的是,如果我生成如上面代码所示的位图,然后将其存储,并在应用程序中读取它(不参考 DICOM)并放入图片框中,则不会发生类似情况。这使我认为问题出在位图本身,但我无法发现,是什么。
我还有一个用 fo-dicom.1.0.37 制作的旧测试应用程序,它在调整大小时不会崩溃。
我很好奇可能是什么原因,如何摆脱这种影响或/以及我可能做错了什么。
(测试应用程序可以从http://jmp.sh/UGOg8Ai下载——我希望如此)。