Graphics.DrawImage throws "Out of Memory" Exception -
10-11-2007
, 07:59 AM
The Graphics.DrawImage method throws "Out of Memory" Exception if the
Matrix.RotateAt(X, Point(100,100), MatrixOrder.Append) was used with a value
of X = 180 + n * 360 where n is an integer.
Code snippet:
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Matrix matrix = e.Graphics.Transform;
matrix.RotateAt(180, m_center, MatrixOrder.Append);
e.Graphics.Transform = matrix;
e.Graphics.DrawImage(m_image, m_rect); // Exception thrown here
matrix.RotateAt(-180, m_center, MatrixOrder.Append);
e.Graphics.Transform = matrix;
}
Stack trace of the Exception:
System.Drawing.Graphics.CheckErrorStatus(Int32 status)
System.Drawing.Graphics.DrawImage(Image image, Int32 x, Int32 y, Int32
width, Int32 height)
System.Drawing.Graphics.DrawImage(Image image, Rectangle rect)
UserDrawnControl.Test.OnPaint(PaintEventArgs e)
System.Windows.Forms.Control.PaintWithErrorHandlin g(PaintEventArgs e, Int16
layer, Boolean disposeEventArgs)
System.Windows.Forms.Control.WmPaint(Message& m)
System.Windows.Forms.Control.WndProc(Message& m)
System.Windows.Forms.ScrollableControl.WndProc(Mes sage& m)
System.Windows.Forms.ContainerControl.WndProc(Mess age& m)
System.Windows.Forms.UserControl.WndProc(Message& m)
System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)
System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG& msg)
System.Windows.Forms.Application.ComponentManager. System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32
reason, ApplicationContext context)
System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32 reason,
ApplicationContext context)
System.Windows.Forms.Application.Run(Form mainForm)
TestUserDrawnControl.Program.Main()
System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)
Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssembly()
System.Threading.ThreadHelper.ThreadStart_Context( Object state)
System.Threading.ExecutionContext.Run(ExecutionCon text executionContext,
ContextCallback callback, Object state)
System.Threading.ThreadHelper.ThreadStart()
Is that a Bug?
It was the thread "Out of Memory Exception in a user drawn control" but
after further investigation of the Problem I thought the title is misleading. |