Bug? Graphics.DrawImage throws "Out of Memory" Exception


G

Guest

Hello,

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.PaintWithErrorHandling(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(Message& m)
System.Windows.Forms.ContainerControl.WndProc(Message& m)
System.Windows.Forms.UserControl.WndProc(Message& m)
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)
System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)

System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(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.RunUsersAssembly()
System.Threading.ThreadHelper.ThreadStart_Context(Object state)
System.Threading.ExecutionContext.Run(ExecutionContext executionContext,
ContextCallback callback, Object state)
System.Threading.ThreadHelper.ThreadStart()

Is that a Bug?

Any help is greatly appreciated.
Thanks Alex
 
Ad

Advertisements

B

Bob Powell [MVP]

This code works fine if the various variables such as m_rect, m_center and
m_image are set correctly.

Do you have a zero size imace or rectangle??

--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.


Alex said:
Hello,

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.PaintWithErrorHandling(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(Message& m)
System.Windows.Forms.ContainerControl.WndProc(Message& m)
System.Windows.Forms.UserControl.WndProc(Message& m)
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32
msg,
IntPtr wparam, IntPtr lparam)
System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)

System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(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.RunUsersAssembly()
System.Threading.ThreadHelper.ThreadStart_Context(Object state)
System.Threading.ExecutionContext.Run(ExecutionContext executionContext,
ContextCallback callback, Object state)
System.Threading.ThreadHelper.ThreadStart()

Is that a Bug?

Any help is greatly appreciated.
Thanks Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top