下面的示例演示了如何使用 ExportToImage 方法,根据图表控件来创建图像。 第一个方法返回指定格式的图像,而第二个方法以指定的格式把图表的图像写入指定的路径中。
C# | 复制代码 |
---|
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
using DevExpress.XtraCharts;
private Image GetChartImage(ChartControl chart, ImageFormat format) {
Image image = null;
using(MemoryStream s = new MemoryStream()) {
chart.ExportToImage(s, Format);
image = Image.FromStream(s);
}
return image;
}
private void SaveChartImageToFile(ChartControl chart, ImageFormat format, String fileName) {
chart.ExportToImage(fileName, format);
}
|
Visual Basic | 复制代码 |
---|
Imports System.IO
Imports System.Drawing
Imports System.Drawing.Imaging
Imports DevExpress.XtraCharts
Private Function GetChartImage(Chart As ChartControl, Format As ImageFormat) As Image
Dim Image As Image = Nothing
Dim s As New MemoryStream()
Try
Chart.ExportToImage(s, format)
Image = Image.FromStream(s)
Finally
s.Dispose()
End Try
Return Image
End Function
Private Sub SaveChartImageToFile(Chart As ChartControl, Format As ImageFormat, FileName As String)
Chart.ExportToImage(FileName, Format)
End Sub
|