Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Processing large images with Delphi for saving as .jpeg

In Delphi 7, I have a library that uses the TCanvas component to output some information. The resulting image is about 4800*6000 pixels and I would like to print it and save it as .jpeg.

To achieve this, I created a TBitmap and gave its Canvas as parameter to the library and then I assigned the bitmap to the jpeg. Apparently, this is taking too much memory, because I am getting an exception when trying to set the bitmap's width and height, saying "Not enough storage is available to process this command."

// output to printer
Printer.BeginDoc();
doPrint(Printer.Canvas);
Printer.EndDoc();

// output in bmp.Canvas
bmp := TBitmap.Create;
bmp.Width := Printer.PageWidth;
bmp.Height := Printer.PageHeight; // <- BAM! Exception!
doPrint(bmp.Canvas);

// save as jpeg
jpg := TJPEGImage.Create;
jpg.Assign(bmp);
jpg.SaveToFile('...');

// free
bmp.Free();
jpg.Free();

What am I doing wrong? Could I save Printer.Canvas directly as a .jpeg file?

Edit: Updated image size approximation from 2000*2000 to 4800*6000

like image 784
Tom Avatar asked Oct 14 '25 15:10

Tom


2 Answers

you should be able to process large bitmaps using TBitmap32 from Graphic32 (http://www.graphics32.org/wiki/)

like image 53
glob Avatar answered Oct 17 '25 10:10

glob


You should set the pixelformat for the bmp to something before sizing up the bmp, as Ben Ziegler suggests. This makes all the difference.

like image 30
Niels Thomsen Avatar answered Oct 17 '25 12:10

Niels Thomsen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!