title: Processing large images with Delphi for saving as .jpeg
body: <p>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 <code>.jpeg</code>.</p>
  
  <p>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."</p>
  
  <pre><code>// 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; // &lt;- BAM! Exception!
  doPrint(bmp.Canvas);
  
  // save as jpeg
  jpg := TJPEGImage.Create;
  jpg.Assign(bmp);
  jpg.SaveToFile('...');
  
  // free
  bmp.Free();
  jpg.Free();
  </code></pre>
  
  <p>What am I doing wrong? Could I save Printer.Canvas directly as a <code>.jpeg</code> file?</p>
  
  <p>Edit: Updated image size approximation from 2000*2000 to 4800*6000</p>