[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

BeeJ

3/30/2012 10:38:00 PM

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.

Question is:
What determines what is max?
Can that be predetermined before allowing the user to create it?

Or do I have to allow the user to try then spank when the error occurs
and tell the user no no and dial back?

The error is trappable and recoverable.

--
Noah's Ark was built by amateurs,
The Titanic was built by professionals.
Row, row, row your boat gently down the stream ...
Life is but a dream!


2 Answers

Mike Williams

3/31/2012 9:36:00 AM

0

"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




Mike Williams

3/31/2012 7:33:00 PM

0

"BeeJ" <nospam@spamnot.com> wrote in message
news:jl5ck5$sv2$1@speranza.aioe.org...
> Question is:
> What determines what is max?

.. . . by the way, in my previous response (using 1600 x 1200 pixel bitmaps
as an example) I said that the number of Autoredraw or other screen
compatible bitmaps you can create is quite limited on many machines, whereas
on all machines you can create up to 350 DIBSections of that size (almost
2GB) before running out of memory. The one thing I forgot to mention is that
you can create those 350 DIBSections /in addition/ to however many
Autoredraw bitmaps the machine will allow, because DIBSections live in your
VB program's 2GB of virtual memory whereas Autoredraw bitmaps live in the
shared memory that is assigned to the graphics card. Your VB program can see
and deal with all of them, despite its otherwise default 2GB memory limit.
You would of course never attempt to create such a huge number of bitmaps
though, not unless you want a very bad slowdown and a lot of disk thrashing
on most machines . . .

.. . . the main point however is that you would not in any case want to
create Autoredraw bitmaps right up to the point you began to run out of
Autoredraw memory (which you appear to be currently doing) because the
shared memory they live in on most machines is then not available for other
programs and some other applications might therefore either run badly or
refuse to run at all. So that's another good reason for using just a few
Autoredraw bitmaps for certain very specific tasks while using mostly
DIBSections for general purposes.

The other thing I forgot to mention is that the much changed way in which
Windows 7 handles display memory means it can actually create quite a lot of
Autoredraw or other screen compatible bitmaps, in many cases at least as
many as it can DIBSections, but of course if you want your program to run on
machines other than Windows 7 (which you almost certainly do) then
DIBSections are clearly the way to go. A few Autoredraw bitmaps are still
extremely useful and they simplify a lot of tasks, but these days it is best
to use them only when you actually need to do so. In the days of gdi32
hardware acceleration of course (before Windows Vista) then Autoredraw and
other screen compatible bitmaps had the very large advantage that they could
live in the graphics card's own memory hardware and could use the graphics
card's gdi32 hardware acceleration for virtually all gdi32 drawing
functions, which made Autoredraw graphics tasks run extremely quickly on
many machines (with the job being carried out by the graphics card's own
processor at the same time as your main program was making full use of its
own main processor thread, but sadly those days are gone for most machines
:-(

Mike