Skip to main content
All docs
V25.1
  • TdxCustomChartControl.ExportToImage(string,TdxSmartImageCodecClass,Integer,Integer) Method

    Exports content to a file in any supported image format.

    Declaration

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

    Parameters

    Name Type Description
    AFileName string

    The absolute or relative path to the resulting image file.

    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 attempts to identify the target format by the specified file name extension. If the extension does not correspond to any supported target image format, 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 file 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 file name extension defines the target format.
    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: Export Chart Content as an Image

    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:

    begin
      dxSavePictureDialog1.Execute(Handle);
      if dxSavePictureDialog1.FileName = '' then Exit;
      // Exports chart content to a file in PNG format
      dxChartControl1.ExportToImage(dxSavePictureDialog1.FileName, TdxGPImageCodecPNG, 400, 500);
    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

    Compiled DevExpress demos ship with source code installed in the Public Documents folder (%Public%) for all users (default). You can find all project and source code files for the Chart control 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. You can specify any of these extensions as a part of the AFileName parameter value when the ACodecClass parameter value is nil (in Delphi) or nullptr (in C++Builder).

      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. The specified file name extension defines the target image format in this case. If the specified file name extension does not match any of the listed extensions, the ExportToImage procedure exports chart content in SVG 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