PC Review


Reply
Thread Tools Rate Thread

clearing old lines in vb.NET

 
 
michael hilton
Guest
Posts: n/a
 
      22nd Sep 2004
Hello all-
I am developing an application that will take serial data from a
compass on a boat, and display it to the screen, like a compass. To
do this i need to draw a line on top of a bitmap, and have it refresh
at ~ 2 times a sec. I am new to vb.NET, it was working fine in eVB.
Here is the code that i have. if i call the fromimage on the bmp on i
want to update, compassBox.image, then the lines are not cleared, just
added on top of all the other lines. this will work for about 30 sec,
then there is an out of memory exception. I belive it is becuase i am
initializing a new bitmap every time, but if i call the dispose() on
temp then the image will not update.
Any help is greatly appreciated. I need to either find a way to clear
the old lines off the initial bitmap, so there is only one line at a
time, or find a way to clean up the memory from the tempBmp, so as to
not cause an exception.
Thanks so much for any help!!
Michael Hilton

''''Code
tempBmp = New Bitmap(PictureBox3.Image)
myGraphics = Graphics.FromImage(tempBmp )
myGraphics.DrawLine(New
System.Drawing.Pen(System.Drawing.Color.LimeGreen), 100, 100, xcoord,
ycoord)
CompassBox.Image = tempBmp
myGraphics.Dispose()
'tempBmp.Dispose() if i uncomment this line, it will not update the
display
''''/Code

An unhandled exception of type 'System.OutOfMemoryException' occurred
in System.Drawing.dll

Additional information: OutOfMemoryException
 
Reply With Quote
 
 
 
 
Alex Feinman [MVP]
Guest
Posts: n/a
 
      23rd Sep 2004
Create an offscreen bitmap that contains an initial image of your compass
display without any lines drawn. Use it as a template.

Dim bitmapOff as new Bitmap( CompassBox.ClientRectangle.Width,
CompassBox.ClientRectangle.Height)
// draw whatever is needed on this bitmap

//here is your update loop called probably from Timer event
tempBmp = New Bitmap(CompassBox.Image)
myGraphics = Graphics.FromImage(tempBmp )
Dim p as new Pen(Color.LimeGreen)
myGraphic.DrawImage( bitmapOff, 0, 0 )
myGraphics.DrawLine(p, 100, 100, xcoord, ycoord)
p.Dispose()
if CompassBox.Image <> Nothing then
' This is needed to avoid OutOfMemory condition
CompassBox.Image.Dispose()
end if
CompassBox.Image = tempBmp
myGraphics.Dispose()


--
Alex Feinman
---
Visit http://www.opennetcf.org
"michael hilton" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello all-
> I am developing an application that will take serial data from a
> compass on a boat, and display it to the screen, like a compass. To
> do this i need to draw a line on top of a bitmap, and have it refresh
> at ~ 2 times a sec. I am new to vb.NET, it was working fine in eVB.
> Here is the code that i have. if i call the fromimage on the bmp on i
> want to update, compassBox.image, then the lines are not cleared, just
> added on top of all the other lines. this will work for about 30 sec,
> then there is an out of memory exception. I belive it is becuase i am
> initializing a new bitmap every time, but if i call the dispose() on
> temp then the image will not update.
> Any help is greatly appreciated. I need to either find a way to clear
> the old lines off the initial bitmap, so there is only one line at a
> time, or find a way to clean up the memory from the tempBmp, so as to
> not cause an exception.
> Thanks so much for any help!!
> Michael Hilton
>
> ''''Code
> tempBmp = New Bitmap(PictureBox3.Image)
> myGraphics = Graphics.FromImage(tempBmp )
> myGraphics.DrawLine(New
> System.Drawing.Pen(System.Drawing.Color.LimeGreen), 100, 100, xcoord,
> ycoord)
> CompassBox.Image = tempBmp
> myGraphics.Dispose()
> 'tempBmp.Dispose() if i uncomment this line, it will not update the
> display
> ''''/Code
>
> An unhandled exception of type 'System.OutOfMemoryException' occurred
> in System.Drawing.dll
>
> Additional information: OutOfMemoryException



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Clearing cells without clearing formulas marsjune68 Microsoft Excel Misc 2 10th Apr 2009 07:39 PM
Clearing dotted lines from Set Print Area Brad Microsoft Excel Discussion 1 13th Jul 2007 03:43 PM
How do I Remove lines above a key word, remove the lines below another, and keep the lines between the to key words in a Text File? Quentin Microsoft VB .NET 2 20th Apr 2007 07:34 PM
Clearing search lines Jack Russell Windows XP Help 1 14th Aug 2005 03:51 PM
Clearing a chart title with less lines of code Don Wiss Microsoft Excel Programming 1 18th May 2004 02:32 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:07 PM.