我最近开始评估 fo-dicom 作为 future 项目的可能 DICOM 库,所以我对它很陌生。
我构建了一个基本的 C# Windows 窗体应用程序,它只读取 DICOM 文件,将其转换为 System.Drawing.Bitmap
并显示在 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: Parameter is not valid.
at System.Drawing.Image.get_RawFormat()
at System.Drawing.Graphics.DrawImage(Image image, Int32 x, Int32 y, Int32 width, Int32 height)
at System.Drawing.Graphics.DrawImage(Image image, Rectangle rect)
at System.Windows.Forms.PictureBox.OnPaint(PaintEventArgs pe)
at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at 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)。
最佳答案
我的一位同事知道答案。以下代码执行此操作:
public partial class TestFoDicomForm : Form
{
private IImage image;
public TestFoDicomForm()
{
InitializeComponent();
this.image = new DicomImage("Image_01.dcm").RenderImage();
Bitmap bmp = image.AsBitmap();
this.pictureBox1.Image = bmp;
}
}
这里的技巧是你需要保存你的 IImage
的实例(由于 RenderImage 的返回类型,必须以这种形式,作为
).IImage
()
关于c# - FO-DICOM:在 C# Windows 窗体应用程序中使用呈现的位图调整窗口大小会导致崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48590344/