Mike Williams
3/31/2012 9:36:00 AM
"BeeJ" <nospam@spamnot.com> wrote in message
news:jl5ck5$sv2$1@speranza.aioe.org...
> Is there a way to determine the maximum image size to allow
> a user to create for user processing without getting the error
> Error 480 "Can't create AutoRedraw image"
> Yes, I can create larger but when going to process that large
> size I get the error message.
You're not actually creating a large image when you initially create a large
Autoredraw PictureBox, you are simply creating a large PictureBox that does
not currently contain a large Autoredraw bitmap. That bitmap is created only
when your code attempts to use it. For example, the simple act of assigning
the PictureBox's hDC to a Long will cause VB to create it, and you can trap
the error at that point.
> Question is:
> What determines what is max?
All PictureBox Autoredraw bitmaps and all bitmaps created using the
CreateCompatibleBitmap API function are screen compatible bitmaps and they
generally live in either the video card's own memory or in memory set aside
by the system specifically for use by the video card. In Windows XP this can
be quite a large amount on the few machines which have high end graphics
cards, but it can be a very low amount on most typical entry level machines.
A limit as low as 0.1 GB is not uncommon. Vista and Win7 machines generally
fare better in this respect because they generally do not use the video
card's hardware memory (or its gdi32 hardware acceleration!) and so they can
be more flexible with the memory they make available, with some machines
allowing as much as 1GB (although even on Vista and Win7 machines a limit of
0.3 GB is not uncommon). Also, the larger the bitmap then the more likely it
is to fail, even if sufficient suitable memory actually still is available,
because the birmap requires one single contiguous block. VB Autoredraw
images (and bitmaps created using the CreateCompatibleBitmap function) are
ideal for many purposes, but you should avoid them when you want to create
lots of large bitmaps.
A far better option for your specific task would be to use DIBSections
instead (have a look at the CreateDIBSection API). That's partly because
DIBSections require only three bytes per pixel instead of the four bytes
required by an Autoredraw bitmap but mostly because DIBSections will happily
live in any memory they can get their hands on, and they can therefore exist
quite happily in all of the 2GB of virtual memory that Windows sets aside
for your VB program.
As an example, if you are creating 1600 x 1200 pixel bitmaps using
Autoredraw (or using CreateCompatibleBitmap) you might be able to create
only 15 of them on some machines (or maybe 40 even 140 or more on other
machines) before you run out of memory, whereas using CreateDIBSection you
will be able to create about 350 of them on virtually all machines, even on
an extremely low end 1GB laptop.
Mike