Solved

Quick question on memory resources in relation to TBitmap components

Posted on 2004-08-11
3
158 Views
Last Modified: 2010-04-05
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.
0
Comment
Question by:mikelittlewood
3 Comments
 
LVL 12

Expert Comment

by:esoftbg
ID: 11773232
> 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
 
LVL 17

Accepted Solution

by:
Wim ten Brink earned 100 total points
ID: 11774086
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
 
LVL 15

Author Comment

by:mikelittlewood
ID: 11781395
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

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question