【发布时间】:2023-04-05 19:34:01
【问题描述】:
我最近开始评估 fo-dicom 作为未来项目可能的 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;
}
}
这段代码可以运行,但是如果我开始resize表单,异常来得比以后告诉要早:
System.ArgumentException:参数无效。
在 System.Drawing.Image.get_RawFormat()
在 System.Drawing.Graphics.DrawImage(图像图像,Int32 x,Int32 y,Int32 宽度,Int32 高度)
在 System.Drawing.Graphics.DrawImage(Image image, Rectangle rect)
在 System.Windows.Forms.PictureBox.OnPaint(PaintEventArgs pe)
在 System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e,Int16 层)
在 System.Windows.Forms.Control.WmPaint(消息&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 下载测试应用程序 - 我希望)。
【问题讨论】: