Skip to main content
All docs
V23.2

TdxCustomChartControl.ExportToImage(TStream,TdxSmartImageCodecClass,Integer,Integer) Method

Exports content to a stream in any supported image format.

Declaration

procedure ExportToImage(const AStream: TStream; ACodecClass: TdxSmartImageCodecClass = nil; AImageWidth: Integer = 0; AImageHeight: Integer = 0); overload;

Parameters

Name Type Description
AStream TStream

The target stream.

ACodecClass TdxSmartImageCodecClass

Optional. The image codec class that corresponds to the required image format. Refer to the following section for the full list of available image formats: Supported Target Formats.

If this parameter is omitted, the procedure exports chart content in SVG format.

AImageWidth Integer

Optional. The exported image width, in pixels. If this parameter is omitted, the target image width matches the current pixel width of the Chart control client area on the parent form.

The export procedure stretches or shrinks the Chart control layout horizontally to fit the resulting image into the target width.

All font sizes remain unchanged. If title or label text does not fit into the corresponding visual Chart element, the Chart control crops the text and ends it with an ellipsis in the exported layout.

AImageHeight Integer

Optional. The exported image height, in pixels. If this parameter is omitted, the target image height matches the current pixel height of the Chart control client area on the parent form.

The export procedure stretches or shrinks the Chart control layout vertically to fit the resulting image into the target height.

All font sizes remain unchanged. If title or label text does not fit into the corresponding visual Chart element, the Chart control crops the text and ends it with an ellipsis in the exported layout.

Remarks

Call the ExportToImage procedure to export content of the Chart control client area to a stream in any supported format. The resulting image size matches the actual pixel dimensions of the Chart control client area on a form.

VCL Chart Control: An Exported Image Example

Supported Target Formats

You can use the optional ACodecClass parameter to specify the required format of the resulting image. The following table lists all possible ACodecClass parameter values:

ACodecClass Parameter Value Image Format File Name Extensions[1] MimeType[2]
nil (in Delphi) or nullptr (in C++Builder)[3] The default image format (SVG).
TdxGPImageCodecBMP Device-Independent Bitmap (BMP/DIB) '*.bmp;' 'image/bmp'
TdxGPImageCodecEMF[4] Enhanced Windows Metafile (EMF) '*.emf;' 'image/emf'
TdxGPImageCodecGIF Graphics Interchange Format (GIF) '*.gif;' 'image/gif'
TdxGPImageCodecJPEG Joint Photographic Experts Group (JPEG) *.jpeg;*jpg; 'image/jpg'
TdxGPImageCodecPNG Portable Network Graphics (PNG) '*.png;' 'image/png'
TdxGPImageCodecTIFF Tagged Image File Format (TIFF) '*.tiff;*.tif;' 'image/tiff'
TdxGPImageCodecWMF[4] Windows Metafile (WMF) '*wmf' 'image/wmf'
TdxSVGImageCodec Scalable Vector Graphics (SVG) '*.svg;' 'image/svg+xml'

Adjust Target Image Dimensions

You can pass required target pixel dimensions for the resulting image as optional AImageWidth and AImageHeight parameters. In this case, the ExportToImage procedure resizes all visible diagrams to fit into the target dimensions. All font sizes remain unchanged.

Code Example

The following code example exports shrunk content of the Chart control client area whose original dimensions on the parent form are 600 by 700 pixels.

var
  AStream: TMemoryStream;
begin
  dxSavePictureDialog1.Execute(Handle);
  if dxSavePictureDialog1.FileName = '' then Exit;
  AStream := TMemoryStream.Create;
  try
    // Exports chart content to a stream in PNG format
    dxChartControl1.ExportToImage(AStream, TdxGPImageCodecPNG, 400, 500);
    AStream.SaveToFile(dxSavePictureDialog1.FileName);
  finally
    AStream.Free;
  end;
end;

VCL Chart Control: An Exported Chart with Three XY Diagrams

To see the export to image functionality in action, run the Chart Control demo in the VCL Demo Center installed with compiled VCL DevExpress demos. Click Export and choose the Export to Image item.

Download: Compiled VCL Demos

Tip

You can find full source code for the installed compiled Chart control demo in the following folder:

%PUBLIC%\Documents\DevExpress VCL Demos\MegaDemos\Product Demos\ExpressChart

Footnotes
  1. This column lists strings of file name extensions associated with corresponding image formats.

    The TdxSmartImageCodec.Extensions class function returns these strings for corresponding TdxSmartImageCodec class descendants listed in the first column.

  2. This column lists multipurpose internet mail extension (MIME) content types associated with corresponding image formats.

    The TdxSmartImageCodec.MimeType class function returns these strings for corresponding TdxSmartImageCodec class descendants listed in the first column.

  3. The default ACodecClass parameter value that corresponds to the SVG image format.

  4. An exported image and its actual dimensions may very significantly depending on the target operating system and its GDI+ library version because Windows Metafile and Enhanced Windows Metafile format implementations rely on the functionality of the native Windows Metafile encoder from the Windows Imaging Component (WIC).

See Also