Solved

Quick question on memory resources in relation to TBitmap components

Posted on 2004-08-11
3
164 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month10 days, 21 hours left to enroll

631 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