How To…Export Gray Scale Jpegs

Question

“Is is possible to export jpegs that are gray scaled?”

Solution

Use the Report.OnFileDeviceCreated event to configure the JPGDevice.Jpeg property. This Jpeg property is of type TJpeg, a Delphi VCL class.

All of the image devices share this common architecture. The BmpDevice has a Bitmap property, the MetaFileDevice has a Metafile property, etc.

Download:  JpgDeviceGrayScale.zip

Sample Delphi Code:

uses
  ppDevice,
  ppFileUtils,
  ppImageDevice;


procedure TForm1.ppReport1FileDeviceCreate(Sender: TObject);
begin

  // configure JPEG to gray scale
  if (ppReport1.FileDevice is TppJPGDevice) then
      TppJPGDevice(ppReport1.FileDevice).JPEG.Grayscale := True;

end; 

procedure TForm1.Button1Click(Sender: TObject);
begin

  ppReport1.TextFileName := TppFileUtils.GetApplicationFilePath + 'myReport.jpg';
  ppReport1.Print;

end;