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