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 / Windows Forms / Drawing / October 2005

Tip: Looking for answers? Try searching our database.

Ever increasing Memory usage!!!

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
TheIlliterate - 22 Oct 2005 13:55 GMT
Hi All
Greetings to all of you. I am a newbie. I am trying to build a
application in C# in which I try to Overlay Bitmap over Video. I am
able to display the bitmap onto video. But my problem arises when
have to Display some rapidly changing Bitmap onto screen(Consider
want to Display time elapsed in seconds so Bitmap updation needs to b
done frequently). My problem is though this kind of animation bu
whenever Bitmap updation occurs it increases memory usage. My memor
usage goes on increasing!!! :(
Ok Let me explain what happens
I have three rectangles A,B,C drawn on to VideoScreen. And say memor
usage is X K
I repaint bitmap this time  rect X is highlighted.        Memory usag
becomes X+300K
I Do a repainting again this time with rect Y being highlighted
Memory usage becomes
X+300K+300K.!!!

No imagine this kind of operation which I have to do after every fe
seconds !!!!
Eventually my whole system becomes non responsive :mad: Please ca
anybody tell me how to stablize memory usage.! Why after every updatio
mem usage increases and does not come back even when updation ha
finished!
(ANd I dont have a window handle I am using VMR9 in windowed mode)
(Sorry I may not be able expalin properly hope I am able to make som
meaning)
please help please help

Regds
The Illiterat

--
TheIlliterat
Bob Powell [MVP] - 23 Oct 2005 11:15 GMT
Whenever you cease using a bitmap you should dispose of it using the
Dispose() method. For best performance however you should probably keep the
same bitmap around and clear it and re-draw your content on it rather than
creating new bitmaps many times a second.

Post some code so we can point you in the right direction.

Signature

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.

> Hi All
> Greetings to all of you. I am a newbie. I am trying to build an
[quoted text clipped - 27 lines]
> Regds
> The Illiterate
TheIlliterate - 25 Oct 2005 07:42 GMT
Hi Bob
Thanks for replying! yes you guessed it right I am using same bitma
rather than creating new bitmap every few seconds. Hence probably i
wouldnt be good idea to dispose bitmap
as long as overlay needs to be shown. Any how I am posting some bit o
code

PHP code
-------------------
   
 
 
 namespace Overlays
 {
 public class Overlay
 {
 public String overlayText;
 public Color overlayTextColor;
 public Color overlayBackgroundColor;
 public String text;
 
 private IVideoWindow vw;
         private    IVMRMixerBitmap9 mbmp;
 
 
 Bitmap masterBmp = null;
 
 Font fon = null;
 private ArrayList arrayGuru;
 float alpha = 0;
 
    
 public Overlay(IVideoWindow vw, IVMRMixerBitmap9 mbmp)
 {
 this.vw = vw;
 this.mbmp = mbmp;
 System.Console.WriteLine("I am in OverlayCS Constructor");
 
 masterBmp = new Bitmap(750, 500, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
 masterBmp.MakeTransparent(Color.White);  
 
 
 //  InitializeDirect3D();
 }
 
 
 
 public void  OffOverlay()
         {
 VMR9AlphaBitmap alphaBmp;
 alphaBmp = new VMR9AlphaBitmap();
 
             int hr = mbmp.GetAlphaBitmapParameters(out alphaBmp);
             Marshal.GetExceptionForHR(hr);
            
 // Disable them
 alphaBmp.dwFlags =VMR9AlphaBitmapFlags.Disable;
 
 // Update the Alpha Bitmap Parameters
 hr = mbmp.UpdateAlphaBitmapParameters(ref alphaBmp);
 Marshal.GetExceptionForHR(hr);
 //masterG
 }
 
 public void  OnOverlay(ArrayList arrList,
 int distBetwSubRect,
 int distance,
 float alpha,
 int indexToBeHighlighted,
 string Action)
 {
 
 Graphics g = null;
 IntPtr hdc;
 IntPtr memDC ;
 IntPtr hBitmap ;
 Bitmap bmp = null;
 VMR9AlphaBitmap alphaBmp;
 alphaBmp =  new VMR9AlphaBitmap();
 this.alpha = alpha;  
 try
 {
 int hr = 0;
 arrayGuru=arrList;
 
 //GetBitmap();
 
 
 
 g = Graphics.FromImage(masterBmp);
 //g.Clear(Color.White);
 Navigate(indexToBeHighlighted, distBetwSubRect, distance);
 hdc = g.GetHdc();
 memDC = NativeMethodes.CreateCompatibleDC(hdc);
 hBitmap = masterBmp.GetHbitmap();
 NativeMethodes.SelectObject(memDC, hBitmap);
 
 // Set Alpha Bitmap Parameters for using a GDI DC
 alphaBmp.dwFlags = VMR9AlphaBitmapFlags.hDC |
 VMR9AlphaBitmapFlags.SrcColorKey |
 VMR9AlphaBitmapFlags.FilterMode;
 
 alphaBmp.hdc = memDC;
 alphaBmp.rSrc = new Foundation.Base.DShowNET.Default.DsRect(0, 0, masterBmp.Width, masterBmp.Height);
 alphaBmp.rDest = GetDestRectangle();
 alphaBmp.clrSrcKey = ColorTranslator.ToWin32(Color.White);
 alphaBmp.dwFilterMode = Foundation.Base.DShowNET.Default.VMRMixerPrefs.PointFiltering;
 alphaBmp.fAlpha = alpha;
 
 // Release GDI handles  
 
 hr = mbmp.SetAlphaBitmap(ref alphaBmp);
 g.ReleaseHdc(hdc);
 g.Dispose();
 
 }
 catch (Exception ex)
 {
 
 }
 finally
 {
 
 //bmp.Dispose();
 // bmp = null;
 g.Dispose();
 g = null;
 GC.Collect();
 }
 }
 
 
 
 NormalizedRect GetDestRectangle()
 {
 NormalizedRect rect = new  NormalizedRect();
 //rect.left =0.2f;
 //rect.top   =0.1f;
 //rect.right  = 0.9f;
 //rect.bottom = 0.3f;
 
 rect.left = 0.0f;
 rect.top = 0.0f;
 rect.right = 1.0f;
 rect.bottom = 0.7f;
 
         return rect;
 }
 
 private void Nav(int indexToBeHighlighted, int distBetwSubRect, int distance)
 {
 try
 {
 
 int y = 0;
 Graphics g = Graphics.FromImage(masterBmp);
 
 g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
 g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
 
 //VMR9AlphaBitmap alphaBmp;
 //alphaBmp = new VMR9AlphaBitmap();
 
 for (int i = 0; i <= 5; i++)
 {
 if (i == indexToBeHighlighted)
 {
 g.DrawRectangle(Pens.Blue, new Rectangle(distance, y, 300, 50));//250
 g.FillRectangle(Brushes.Black, new Rectangle(distance, y, 300, 50));
 using(Font fon = new Font("Courier",18))
 g.DrawString(arrayGuru[i].ToString(),fon , Brushes.Blue, (distance + 25), (y+2));//275
 y = y + distanceBetweenSubtitleRectangles;//150
 }
 else
 {
 g.DrawRectangle(Pens.WhiteSmoke, new Rectangle(distance, y, 300, 50));//250
 g.FillRectangle(Brushes.Black, new Rectangle(distance, y, 300, 50));
 using(Font fon = new Font("Courier",18))
 g.DrawString(arrayGuru[i].ToString(), fon, Brushes.WhiteSmoke, (distance + 25), (y+2));//275
 y = y + distanceBetweenSubtitleRectangles;//150
 }
 }
 g.Dispose();
 
 }
 catch(Exception ex)
 {
 
 
 }
 
 
 
 }
 }
 }
--------------------

regds
TheIlliterate

Signature

TheIlliterate

TheIlliterate - 26 Oct 2005 05:44 GMT
Hey no suggestions at all !?  :

--
TheIlliterat

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.