qmp Posted June 8, 2005 Posted June 8, 2005 Ok.. I have a picChart picturebox on my form that resizes with the form. It is double buffered by me so when the picChart chagnes size, I must resize my backbuffer... I can do any of my drawing at any time using GDI+ and memDC. It works very well and my picChart is redrawn any time the user drags stuff over it. bitblt seems very fast as well although memDC.DrawLine does not seem as fast as GDI MoveToEx and LineTo.. but its very easy to implement. When the user resizes the form, i get SEVERE memory leaks.. I am completely lost now. I can't figure out the solution. I have tried using a static backbuffer size and instantiate it outside of the resize form but that still does not work. I'm at a loss now. private Graphics memDC; IntPtr memdc; private void picChart_Resize(object sender, EventArgs e) { // If we have already created a dc for mem, lets free it up first if (memdc.ToInt32() != 0) DeleteDC(memdc); // Resize our backbuffer Bitmap memBmp = new Bitmap(picChart.Width, picChart.Height, System.Drawing.Imaging.PixelFormat.Format16bppRgb555 ); Graphics clientDC = picChart.CreateGraphics(); IntPtr hdc = clientDC.GetHdc(); memdc = CreateCompatibleDC(hdc); SelectObject(memdc, memBmp.GetHbitmap()); memDC = Graphics.FromHdc(memdc); // Clean up DeleteObject(memBmp.GetHbitmap()); clientDC.ReleaseHdc(hdc); clientDC.Dispose(); memBmp.Dispose(); // Clear out our back buffer memDC.FillRectangle(new SolidBrush(Color.Black), 0, 0, picChart.Width, picChart.Height); } private void picChart_Paint(object sender, PaintEventArgs e) { // Copy Region from memDC IntPtr hdc = e.Graphics.GetHdc(); IntPtr hMemdc = memDC.GetHdc(); BitBlt(hdc, e.ClipRectangle.X, e.ClipRectangle.Top, e.ClipRectangle.Width, e.ClipRectangle.Height, hMemdc, e.ClipRectangle.X, e.ClipRectangle.Y, 0x00CC0020); e.Graphics.ReleaseHdc(hdc); memDC.ReleaseHdc(hMemdc); } Quote
IngisKahn Posted June 8, 2005 Posted June 8, 2005 Just taking a quick scan I see you're creating a brush without disposing it. Use Brushes.Black instead. Quote "Who is John Galt?"
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.