Memory problem with images

A

alberto.decaro

Hello everybody,
I'm developing a ppc application that receives images from a url and
periodically displays them in a picturebox (I use a timer control).

private sub tick(...) handles myTimer.tick
'pbx is the target picturebox control
pbx.image = getImage()
end sub

private function getImage() as bitmap
'strUrl is the stream containing the image
return new bitmap(strUrl)
end function

The problem is that at each ticking a new bitmap object is created
exhausting memory resources.
I'd like creating a bitmap object once and using a '.FromStream' method
at each ticking, but the Image.FromStream static method is not
evailable for the compact framework.

Any clue?
 
S

Sergey Bogdanov

Try to explicitly dispose image before assigning the new one to a
picture box:

private sub tick(...) handles myTimer.tick
'pbx is the target picturebox control
if pbx.image is nothing then pbx.image.Dispose()
pbx.image = getImage()
end sub

About your second question:- the Bitmap class has Stream parameter in
one of its constructors:

Bitmap b = new Bitmap(Stream);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top