Back to Devexpress

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

vcl-dxchartcontrol-dot-tdxcustomchartcontrol-dot-exporttoimage-x28-system-dot-classes-dot-tstream-dxsmartimage-dot-tdxsmartimagecodecclass-system-dot-integer-system-dot-integer-x29.md

latest8.8 KB
Original Source

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

Exports content to a stream in any supported image format.

Declaration

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

Parameters

NameTypeDescription
AStreamTStream

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.

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 ValueImage FormatFile Name Extensions[1]MimeType[2]
nil (in Delphi) or nullptr (in C++Builder)[3]The default image format (SVG).
TdxGPImageCodecBMPDevice-Independent Bitmap (BMP/DIB)'*.bmp;''image/bmp'
TdxGPImageCodecEMF[4]Enhanced Windows Metafile (EMF)'*.emf;''image/emf'
TdxGPImageCodecGIFGraphics Interchange Format (GIF)'*.gif;''image/gif'
TdxGPImageCodecJPEGJoint Photographic Experts Group (JPEG)*.jpeg;*jpg;'image/jpg'
TdxGPImageCodecPNGPortable Network Graphics (PNG)'*.png;''image/png'
TdxGPImageCodecTIFFTagged Image File Format (TIFF)'*.tiff;*.tif;''image/tiff'
TdxGPImageCodecWMF[4]Windows Metafile (WMF)'*wmf''image/wmf'
TdxSVGImageCodecScalable 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 (original dimensions on the parent form are 600 by 700 pixels).

delphi
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;
cpp
TMemoryStream *AStream = nullptr;
  // ...
  dxSavePictureDialog1->Execute(Handle);
  if(dxSavePictureDialog1->FileName == "") { return; }
  AStream = new TMemoryStream();
  try
  {
    // Exports chart content to a stream in PNG format
    dxChartControl1->ExportToImage(AStream, __classid(TdxGPImageCodecPNG), 400, 500);
    AStream->SaveToFile(dxSavePictureDialog1->FileName);
  }
  __finally
  {
    delete AStream;
  }

To see the export to BMP functionality in action, run the Chart Control demo in the VCL Demo Center installed with compiled DevExpress VCL demos. Click Export and choose the Export to Image option to export chart content in any supported image format.

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_

Other Export Methods

You can call the following procedures to export chart content to a file or stream in other formats:

ExportToBMP | ExportToGIF | ExportToJPEG | ExportToPNG | ExportToSVG | ExportToTIFFExport the current state of the Chart control client area as an individual image in corresponding formats.ExportToDOCX | ExportToXLSXExport the current state of the Chart control client area as an inline or floating image in the resulting DOCX or XLSX document.ExportToEMF | ExportToWMFExport the current state of the Chart control client area as an individual image in Windows Metafile (EMF and WMF) formats.

Footnotes

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

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

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

  4. An exported image and its actual dimensions may vary 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

TdxCustomChartControl.ExportToImage(System.String,dxSmartImage.TdxSmartImageCodecClass,System.Integer,System.Integer) Procedure

TdxCustomChartControl Class

TdxCustomChartControl Members

dxChartControl Unit