Solved

Quick question on memory resources in relation to TBitmap components

Posted on 2004-08-11
3
156 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now