Only load actually visible items?

S

Simon [2610]

Hi,

Im building an application to use instead of the explorer thumbnail
view.
Lets say i have a folder with 2500 images, and at any given time i can
show 25 images at thumbnail size on my screen. I have a control
(PictureControl, PC) on which i have a picturebox to display the
individual images, and a label for the name.
Ive loaded all theese 2500 controls onto a FlowLayoutPanel.
Now i want an event to fire when i scroll and a PC becomes visible, so
that i can load the image then, and when it leaves the visible area i
can unload the image. so that i use a minimal amount of memory.
I thought the visiblechanged event was what i needed, but they are
always visible :/

I am building this because im getting tired of waiting for windows to
finish producing the thumbnails when i view a folder, and have found
no way to force windows to load all the thumbnails without me
scrolling down and looking at them (and even then it can seem like its
stalling).

Now, i have thought of an alternate way, if i can get the percentage
position (or something like that) of the scroll bar, i can calculate
what is and what isnt visible... but i would rather the application to
tell my controls which are visible to the user and which arent.

anyone got a solution for that one? ive searched the web without any
luck, but perhaps im searching for the wrong things?

Regards
Simon.
 
T

Tim Roberts

Simon said:
Im building an application to use instead of the explorer thumbnail
view.
Lets say i have a folder with 2500 images, and at any given time i can
show 25 images at thumbnail size on my screen. I have a control
(PictureControl, PC) on which i have a picturebox to display the
individual images, and a label for the name.
Ive loaded all theese 2500 controls onto a FlowLayoutPanel.
Now i want an event to fire when i scroll and a PC becomes visible, so
that i can load the image then, and when it leaves the visible area i
can unload the image. so that i use a minimal amount of memory.

That's a false optimization. 2500 thumbnails at 64x64 true color totals
only 30 megabytes of memory. Absolutely trivial.
I thought the visiblechanged event was what i needed, but they are
always visible :/

Really, the whole point of a FlowLayoutPanel is that you don't have to
worry about when controls come and go. You might consider using a
different kind of container, where you can intercept the scroll operations
and update the images manually.
I am building this because im getting tired of waiting for windows to
finish producing the thumbnails when i view a folder, and have found
no way to force windows to load all the thumbnails without me
scrolling down and looking at them (and even then it can seem like its
stalling).

Well, you only pay that penalty the first time, until it builds the
thumbnail database. Are you sure you can build the thumbnails faster? It
takes time to read a large image file.
 
S

Simon [2610]

As you've found, the Visible property has nothing to do with clipping.
It's simply a question of whether the control is shown when it's
scrolled to an unclipped position on the screen.


For what it's worth, it seems to me that if you delay loading of the
thumbnails until the item is visible on the screen, you would run into
the same behavior Windows already has and which you don't like.

Yes that is partially true, but what i will avoid the thumbnail
generating stalling, as i have seen it in windows - sometimes for up
to 30 seconds even in folders with only 300 images. Also i was
thinking of loading the images in several threads and taking advantage
of multicore cpu. When windows loads thumbnails it seems like it
doesnt use that much cpu power.
The best approach for what you're doing is to use the ListView control,
which supports a "virtual mode".  In that mode, you have to respond to
certain events that allow you to manage a cache of items and provide
just the items that are actually visible.

I will probably try doing the listview control approach. will be
interesting to see if it fits my needs :)
- i did however continue my search yesterday, and found someone with a
similar problem - he was adviced to check the controls bounds against
the containers clientrectangle - i implemented this in my app, and it
seems to do the trick - i narrowed the search for controls by taking
the currentscrolling position dividing it by the maximum (to get the
percentage used) and then finding that position in a list of
PictureControls which improved the speed a lot compared to going
through all of the controls (just thought id share if anyone else
comes upon this thread with a similar problem).
If that doesn't provide enough control for your needs, you'll probably
have to implement a custom control yourself that does the management of
the thumbnails in the way you want.  The ListView control is pretty
flexible so if it can't do what you want, there's probably nothing else
in the stock Forms controls that will.  (WPF might have something
similar that works differently/better-suited to your needs, but I don't
know as much about that).

Thanks for sharing your thoughts on this matter!

regards
Simon
 
S

Simon [2610]

That's a false optimization.  2500 thumbnails at 64x64 true color totals
only 30 megabytes of memory.  Absolutely trivial.

i didnt think of actually converting to thumbnail size and using those
images, just loading the original ones ( which often will be 5mb+)..
but that may be a good idea. my thumbnails are a little larger
(120x120) but still even with 10000 images it should be a manageable
amount of memory.
Really, the whole point of a FlowLayoutPanel is that you don't have to
worry about when controls come and go.  You might consider using a
different kind of container, where you can intercept the scroll operations
and update the images manually.


Well, you only pay that penalty the first time, until it builds the
thumbnail database.  Are you sure you can build the thumbnails faster?  It
takes time to read a large image file.

i did a thumbnail generator a few months back, which went really fast
with 8 threads. The largest problem with the windows thumbnail view is
when it stalls and i have to wait for 30 seconds for it to pick up
again, i can avoid this in my own program cause ill decide for it what
to do :)

Thanks for your time!

best regards
Simon
 
T

Tim Roberts

Simon said:
i didnt think of actually converting to thumbnail size and using those
images, just loading the original ones ( which often will be 5mb+)..

2500 images at 5MB is 12GB. No matter how many threads you use, it takes a
full minute or more just to read that much data from disk...
 

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