Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / October 2007

Tip: Looking for answers? Try searching our database.

Out of Memory Exception in a user drawn control

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Alex - 10 Oct 2007 11:30 GMT
Hello,

I am drawing a control with GDI+. It contains an image which turns around a
center.

After turning for a while I get and "Out of Memory" Exception. I am
disposing all the created objects(the ones which are used/created during
turning).

The image is included in the solution as an embedded resource, loaded into a
stream and than created with new Bitmap. But it is always the same image and
I am laoding it only once.

When the Exception occurs the Control is just lost on the screen and instead
i see red framed square with is crossed out.

The Code where the Exception is thrown:

       private void OnPaint(Graphics graphics)
       {
               Matrix matrix = new Matrix();
               matrix.RotateAt(Angle, m_center, MatrixOrder.Append);
               graphics.Transform = matrix;
               graphics.DrawImage(m_image, m_rect);
               matrix.RotateAt(-Angle, m_center, MatrixOrder.Append);
               graphics.Transform = matrix;
               matrix.Dispose();
       }

Thanks for any help
Alex
Göran Andersson - 10 Oct 2007 12:20 GMT
> Hello,
>
[quoted text clipped - 27 lines]
> Thanks for any help
> Alex

You are disposing the Matrix object taht you just assigned to the
Graphics object. That means that the Graphics object contains a Matrix
object that is no longer valid.

Get the Matrix object that the Graphics object contains from start, then
put that back when you are done.

Signature

Göran Andersson
_____
http://www.guffa.com

Alex - 11 Oct 2007 10:08 GMT
> > Hello,
> >
[quoted text clipped - 34 lines]
> Get the Matrix object that the Graphics object contains from start, then
> put that back when you are done.

I did that but It didn't solve the problem, I still get the Out of Memory
Exception after turning the object several times.

        {
                Matrix matrix = new Matrix();
                Matrix save = graphics.Transform;
                matrix.RotateAt(Angle, m_center, MatrixOrder.Append);
                graphics.Transform = matrix;
                graphics.DrawImage(m_image, m_rect);
                matrix.RotateAt(-Angle, m_center, MatrixOrder.Append);
                graphics.Transform = matrix;
                graphics.Transform = safe;
                matrix.Dispose();
        }
Göran Andersson - 11 Oct 2007 13:18 GMT
>> Get the Matrix object that the Graphics object contains from start, then
>> put that back when you are done.
[quoted text clipped - 13 lines]
>                  matrix.Dispose();
>          }

You put the matrix in the variable "save", then try to read it from the
variable "safe"?

I suppose that's just a typo, but you should consider to post the code
that you are actually using instead of some other code that you are not
using. Noone can find an error in your code by looking at some other code.

Signature

Göran Andersson
_____
http://www.guffa.com

Alex - 11 Oct 2007 13:01 GMT
After further investigation of the Problem I thought the title is misleading,
I opened a new thread "Graphics.DrawImage throws "Out of Memory" Exception".

> > Hello,
> >
[quoted text clipped - 34 lines]
> Get the Matrix object that the Graphics object contains from start, then
> put that back when you are done.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.