下面的示例演示了如何使用 ExportToImage 方法,根据图表控件来创建图像。 第一个方法返回指定格式的图像,而第二个方法以指定的格式把图表的图像写入指定的路径中。

C#CopyCode image复制代码
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);
}
Visual BasicCopyCode image复制代码
Imports System.IO
Imports System.Drawing
Imports System.Drawing.Imaging
Imports DevExpress.XtraCharts
' ...

Private Function GetChartImage(Chart As ChartControl, Format As ImageFormat) As Image
   ' Create an image.
   Dim Image As Image = Nothing
   
   ' Create an image of the chart.
   Dim s As New MemoryStream()
   Try
      Chart.ExportToImage(s, format)
      Image = Image.FromStream(s)
   Finally
      s.Dispose()
   End Try
   
   ' Return the image.
   Return Image
End Function

Private Sub SaveChartImageToFile(Chart As ChartControl, Format As ImageFormat, FileName As String)
   ' Create an image in the specified format from the chart
   ' and save it to the specified path.
   Chart.ExportToImage(FileName, Format)
End Sub