2009-12-31 2 views
2

.NET 2.0의 Windows Forms 응용 프로그램에서 양식을 사용하고 PictureBox의 ImageLocation 속성을 설정하여 애니메이션 GIF로로드합니다. 애니메이션은 다음 프레임을 렌더링하는 것이 시간이되면, 나는 다음과 같은 예외 스택 추적 얻을 :애니메이션 GIF를 사용하여 PictureBox를로드 한 후 "일반 오류가 GDI +에서 발생했습니다"

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() 

답변

0

내가 이런 이유 완전히 확실하지 않다, 그러나 나는 해결 방법을 발견했다. PictureBox의 WaitOnLoad 속성을 True로 설정했습니다. False (기본값)로 변경하면 문제가 해결됩니다.

0

여러 페이지 티프를 다루는 관련 문제를 발견했습니다. "pictureBox1.Load (fileName)"을 사용하고 pictureBox1.Image.SelectActiveFrame (FrameDimension.Page, index)을 사용합니다. pictureBox1.Image.SelectActiveFrame에 대한 호출이 "GDI +에서 일반 오류가 발생했습니다"예외를 throw합니다.

이미지가로드되는 방식에 문제가 있습니다.

나는 사용하여 이미지를로드 할 때 :

Image _myImage = Image.FromFile(fileName); 

을 다음 pictureBox1에 할당 :

pictureBox1.Image = _myImage; 

다음 호출이 제대로 작동 :

pictureBox1.Image.SelectActiveFrame(FrameDimension.Page, index); 
2

mcdon의 대답은 가까이, 실제로 심지어 옳다. 문제는 PictureBoxImageLocation 속성의 파일에서 그림을로드하게하면 Load() 실행 후 스트림이 닫히고 전에 전에 모든 스트림이로드 된 것입니다 (첫 번째 프레임 만로드 될 수 있음). 따라서 Image.FromFile()을 사용하여 Image 개체에 그림을 수동으로로드하고이 개체를 Image 속성을 통해 PictureBox에 제공하면이 문제를 방지 할 수 있습니다.

관련 문제