Board index » cppbuilder » Storing a number of TBitmaps in memory

Storing a number of TBitmaps in memory


2004-06-16 02:04:56 PM
cppbuilder48
Hi.
I m building a custom component from TScrollBox. This component will
display rows and columns of pictures.
Each picture is a separate object which holds one TBitmap and some other
memory objects like TStringList.
The component will accept a big list of the PictureItems metioned above
first. Then it would load the TBitmap then display only if the
PictureItem comes into the viewport.
In Win98, I get "Not enough storage available to process this command"
when i disply about 320 pictures.
I tried to solve this problem by calling Dormant() and FreeImage() as
soon as the TBitmap is loaded. But that didn't fix it.
I understand that each TBitamp will consume one Windows handle and
that's what causing this error.
There are two work-arounds that i came up...
1) Only keep a small number of Bitmaps.
2) Instead of TBitmap, use TMemoryStream in the PictureItem. I hope
TMemoryStream doesn't require any Windows handles.
Please let me know if I m thinking straight. And which work-around is
more right.
Thanks for you time.
Jaepil Kim
 
 

Re:Storing a number of TBitmaps in memory

Hi Jaepil,
If your component displays thumbnails of the same size, you could load them
into an image list. An image list uses a single bitmap to hold a number of
equal sized images, thus consuming only one resource handle. Have a look at
TImageList in the online help. When a thumbnail is scrolled into view, you
can dynamically load the actual (full size) bitmap to display it, and unload
the bitmap when it is scrolled out of view.
If your component needs to display images of different sizes, you may need
to set up a caching scheme, which loads only a small number of images as
they are needed to be displayed and unload them when they are not needed
anymore.
Hope this helps,
Martin