Tbitmap.SaveFile gets Out of system Resources!!

Tbitmap.SaveFile gets Out of system Resources!!

Post by Tarvird » Sun, 04 Feb 2007 15:17:43

Dear friends,
I have a multithread application. In background thread I use Tbitmap to
create a special report and save it as BMP file. But when I want to save it
to file sometimes(some computers and sometimes, not always!!) get exception
"Out of system resources".
why? and why not always? what can I do? is it related to thread resource
should I do it on main thread!!?
My source is as bellow
bmp := TBitmap.Create;
with bmp do begin
Monochrome := true;
PixelFormat := pf1bit;
SetSize(PageWidth,PageHeight); // A4 Size
Canvas.Brush.Style := bsClear;

bmp.SaveToFile(BMPFileName); //???? sometimes get exception "out of system


Tbitmap.SaveFile gets Out of system Resources!!

Post by Nils Haec » Mon, 05 Feb 2007 06:04:09

Hi Tarvirdi,

This is probably because of the size of your bitmap. What size are you
creating? For older systems (esp. 90/98/ME), and depending on graphics
cards, these sizes are rather limited.

A rule of thumb is to never create a bitmap larger than the screen size.

So what you can do is divide and conquer: if your page is too large, split
it into 2 halves, and print each halve. If the halves are still too big,
split these into halves, etcetera.

On second thoughts, it is weird though that this happens at the moment of
calling SaveToFile. I'd expect it to happen when calling SetSize, or at
least when using the handle through the Canvas property. But perhaps GDI
fumbles a bit with your system resources the moment the bitmap gets saved.
Maybe Peter Below can shed a light on this.

Hope that helps,


"Tarvirdi" < XXXX@XXXXX.COM > schreef in bericht