Skip to main content
A newer version of this page is available.

ChartControl.ExportToImage(Stream, ImageFormat) Method

Creates an image file in the specified format from the current chart and exports it to a stream.

Namespace: DevExpress.XtraCharts

Assembly: DevExpress.XtraCharts.v18.2.UI.dll

Declaration

public void ExportToImage(
    Stream stream,
    ImageFormat format
)

Parameters

Name Type Description
stream Stream

A Stream object to which the current chart is exported.

format ImageFormat

A ImageFormat value representing the format in which the chart is exported.

Remarks

Use this method to export the current chart as an image to an object of the Stream class or its descendants. The image format should be specified by the format parameter, for instance, ImageFormat.BMP. After creating an image file, the chart can be displayed in an appropriate application.

To show the standard Print dialog, use the ChartControl.Print method. The dialog allows end-users to print the chart, select the printer (if required), specify the range of pages to print, the number of copies, etc.

To display the DevExpress Print Preview use one of the following methods.

Method Description
ChartControl.ShowPrintPreview Creates the print document and displays the Print Preview of the document.
ChartControl.ShowRibbonPrintPreview Creates the print document and displays the Print Preview with the Ribbon toolbar of the document.

To export the chart, use the appropriate ExportTo~ method (e.g., ChartControl.ExportToHtml, ChartControl.ExportToPdf, etc.)

Important

Note that, exporting to raster and vector images is implemented by the Chart and does not require any library.

The chart can be previewed, printed and exported to other formats only if the Printing library is available. Make sure you add a reference to the DevExpress.XtraPrinting.v18.2 assembly.

Also note that chart export to PDF requires the DevExpress.Pdf.Core library to be available.

Example

The following example demonstrates how to use the ExportToImage method to create an image from a chart control. The first method returns the image in the specified format, while the second writes the chart’s image in the specified format to the specified path.

using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
using DevExpress.XtraCharts;
// ...

private Image GetChartImage(ChartControl chart, ImageFormat format) {
   // Create an image.
   Image image = null;

   // Create an image of the chart.
   using(MemoryStream s = new MemoryStream()) {
      chart.ExportToImage(s, format);
      image = Image.FromStream(s);
   }

   // Return the image.
   return image;
}

private void SaveChartImageToFile(ChartControl chart, ImageFormat format, String fileName) {
   // Create an image in the specified format from the chart
   // and save it to the specified path.
   chart.ExportToImage(fileName, format);
}

The following code snippets (auto-collected from DevExpress Examples) contain references to the ExportToImage(Stream, ImageFormat) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also