gpt4 book ai didi

.net - "A generic error occurred in GDI+"加载带有动画 GIF 的 PictureBox 后

转载 作者:行者123 更新时间:2023-12-05 00:56:03 25 4
gpt4 key购买 nike

我有一个 .NET 2.0 中的 Windows 窗体应用程序,窗体上有一个 PictureBox,我通过设置 PictureBox 的 ImageLocation 属性用动画 GIF 加载它。当动画渲染下一帧时,我得到以下异常和堆栈跟踪:

A generic error occurred in GDI+.
at System.Drawing.Image.SelectActiveFrame(FrameDimension dimension, Int32 frameIndex)
at System.Drawing.ImageAnimator.ImageInfo.UpdateFrame()
at System.Drawing.ImageAnimator.UpdateFrames()
at System.Windows.Forms.PictureBox.OnPaint(PaintEventArgs pe)
at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)
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.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at AIRNow.IMS.Mapper.MapWizard.Main() in C:\Projects\AIRNowI\IMS\UserInterface\MapWizard\MapWizard.cs:line 14
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

最佳答案

mcdon 的回答很接近,甚至是正确的。问题是,如果您让 PictureBoxImageLocation 属性中命名的文件中加载图片,则流可能会在执行 Load() 后关闭,但之前所有帧都已加载(可能仅加载第一帧)。因此,如果您使用 Image.FromFile() 将图片手动加载到 Image 对象,并将该对象提供给 PictureBox,就可以避免这种情况通过其 Image 属性。

关于.net - "A generic error occurred in GDI+"加载带有动画 GIF 的 PictureBox 后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1983223/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com