Quick question on memory resources in relation to TBitmap components

This doesnt happen all the time, but it is annoying when it does occur.

After Ive created a TBitmap image,
I then assign
Bitmap.Width := printer.pagewidth
and
Bitmap.Height := printer.pageheight

Sometimes though when it trys to assign the second size variable to the image, it throws an exception saying it doesnt have the resources to allocate (cant remember the exact message as Im not at my own PC).
Anyone had this problem before? Do I need to physically allocate memory space to create a large image canvas?
I wouldnt have thought this would be an issue.
LVL 15
mikelittlewoodAsked:
Who is Participating?
 
Wim ten BrinkConnect With a Mentor Self-employed developerCommented:
Let's see... Assume you have a 300 DPI printer. You create a truecolor bitmap at the size of the paper. Say, 8" by 11"... So you get a total size of (8x300) x (11x100) = 7.920.000 pixels. Since it's truecolor with Alpha-channels, you have to multiply by 4 to get the amount of memory required... Thus a total of 31.680.000 bytes, or over 30 MB in memory that will be required.

Now, I do assume your system can handle this much memory... If you don't then, well... You know where the problem lies then.

But what if you attach a high-quality 1200 DPI printer? The width becomes 4 times larger, the height is 4 times larger, thus the amount of memory is 16 times larger, for a nice 483 MB of memory. I doubt you have this much memory, though. If your printer is only 600 DPI then it's only about 121 MB in size.

Allocating the memory isn't an issue if you have all this memory available. Still you can reduce the size a bit by setting the TBitmap.Monochrome property to true. Useful on a black&white printer since it reduces the size by a factor 32. Thus your 300 DPI printer would just generate a bitmap of 1 MB, not 30 MB. You can also set the PixelFormat property to a lower number of colors, like pf4bit. By default your bitmap is probably 32-bits per pixel. Setting it to 4 bits per pixel already reduces the size by a factor 8. Too bad colors will degrade.

Working with images will eat a lot of resources, especially if you make them huge...
0
 
esoftbgCommented:
> as Im not at my own PC
I just guess: May be the PC you working at has not attached a printer at all ?
0
 
mikelittlewoodAuthor Commented:
I should have enough memory to deal with the bitmap, but Ill try setting the Mono property to true and see how that works.
Im only doing black and white anyway.
0
All Courses

From novice to tech pro — start learning today.