Re: too many picture controls really slows down my application
- From: Mike Williams <gagamomo@xxxxxxxxxxx>
- Date: Tue, 11 Dec 2007 02:58:17 -0800 (PST)
On 11 Dec, 02:49, "Guy" <some...@xxxxxxxxxxxxxxx> wrote:
I have a folder with about 50 pictures which
I want to load on my form. I load them in an
array of picture controls, 12 on the form at
a time. I then have a scroll bar which allows
me to scroll through the whole folder. If I do
load 12 pictures at a time (4 across x 3 high),
they load pretty quickly, about 1/2 second each.
If I load 20 at a time, they start loading
quickly but after about 15 pictures or so, they
start to take several seconds each. In my WinXP,
when I use Windows Explorer to view that same
folder, it loads "all 50 pictures" in less than
one seconds.
As Beastfish has already said, Explorer is fast because it is not
actually loading the pictures. It instead loads ready prepared
thumbnails from a cache. In your case you are loading the actual
pictures, which is why each one takes about half a second on your
machine because that's about how long it takes to load and decode and
resize for viewing a normal sized jpeg photo. (I assume that by
"picture controls" you actually mean "image controls" and not "picture
boxes" so that the image control automatically reduces the size for
you to create a suitably sized thumbnail?).
Anyway, the half a second that you are reporting for loading such a
jpeg is fairly typical. If you want it to be faster than that then
you've got to create small thumnbnails in advance (which of course
will take the half a second anyway, but it will have been done in
advance) and in that case you might like to give Beastfish's code a
look. I haven't looked at it myself, but knowing Beastie I'm sure it
does exactly what it says on the tin :-)
Regarding your dramatic slowdown when you begin to load 15 or 20 or
more pictures (where you say it starts to take several seconds) there
is a reason for that as well, and it can be fixed so that you get back
to your "half a second per image" no matter how many thumbnails you
display, which is as fast as you're going to get without using a pre-
prepared thumbnail cache.
When your code loads a jpeg into the Picture property of a Form or a
PictureBox or an Image Control, or into a stdPicture Object, it loads
the full jpeg and converts it to a full sized bitmap (because Windows
can only natively deal with and display bitmaps and metafiles and a
few other formats). If the specific control happens to have a facility
for automatically stretching the bitmap (an Image Control with its
Stretch property set to True, which I assume is what you are using) it
will then create a reduced size bitmap for display purposes. However,
in all cases, the full sized bitmap will remain in memory, ready for
further use when your code requires it. The bitmap of course will be
very much larger than the jpeg it respresents, for example a 24 bit
1600 x 1200 bitmap of an original 400K jpeg will be about 5.5
megabytes. So, by the time you've got 20 such jpegs loaded you've got
at least 110 megabytes of data loaded. Windows of course uses lots of
memory for other purposes all the time, and by the time you've got 110
megabytes of image data you will be running out of real memory on many
machines. Windows will then start to use its swap file on disk instead
of real memory, hence the drastic reduction in speed.
Anyway, the trick is to NOT load all of this stuff in the first place.
Just load the first jpeg into a Picture Box (a hidden picture box
would be fine) and use PaintPicture to draw a reduced size thumnbnail
of it into an Autoredraw visible Picture Box (or into some other
screen compatible memory buffer). Then load the second jpeg into the
same hidden Picture Box, so that it replaces the first, and use
PaintPicture to draw a thumbnail of this second jpeg in the Autoredraw
visible Picture Box so that it is positioned next to the first
thumbnail, etc, etc. In this way only one full sized bmp of a jpeg is
ever in memory at any one time, with only the bitmap thumbnails of all
the others being in memory (in the visible Autoredraw Picture Box),
which of course are very much smaller. You can then place that
Autoredraw Picture Box inside another ordinary picture box and use
scroll bars to allow the user to alter its Top and / or Left
properties so as to scroll through all the thumbnails.
Anyway, it's still early morning (for me!) and I haven't had my
cornflakes yet (!) and I've probvably missed a few details, but that's
a rough outline of what you need to do
Mike
.
- Follow-Ups:
- References:
- Prev by Date: Re: too many picture controls really slows down my application
- Next by Date: Re: too many picture controls really slows down my application
- Previous by thread: Re: too many picture controls really slows down my application
- Next by thread: Re: too many picture controls really slows down my application
- Index(es):
Relevant Pages
|
Loading