Syncfusion.XlsIO.Base
Example 


Stream object where the image is streamed.

SaveAsImage Method (IChart)

Converts the chart to image stream.
Syntax
'Declaration
 
Sub SaveAsImage( _
   ByVal imageAsStream As Stream _
) 
'Usage
 
Dim instance As IChart
Dim imageAsStream As Stream
 
instance.SaveAsImage(imageAsStream)
void SaveAsImage( 
   Stream imageAsStream
)

Parameters

imageAsStream
Stream object where the image is streamed.
Example
The following code illustrates how a chart in the worksheet/workbook can be converted to an image.
using Syncfusion.XlsIO;
using System.IO;
using System.Drawing;
using Syncfusion.ExcelChartToImageConverter;
            
class Program
{
    static void Main(string[] args)
    {  
        using (ExcelEngine excelEngine = new ExcelEngine())
        {
            //Create worksheet
            IApplication application = excelEngine.Excel;
            application.DefaultVersion = ExcelVersion.Excel2013;
            IWorkbook workbook = application.Workbooks.Create(1);
            IWorksheet sheet = workbook.Worksheets[0];                                           
            
            //Add data
            sheet.Range["A1"].Text = "Jan";
            sheet.Range["B1"].Text = "Feb";
            sheet.Range["C1"].Text = "Mar";
            sheet.Range["A2"].Value = "10";
            sheet.Range["B2"].Value = "20";
            sheet.Range["C2"].Value = "30";
            
            //Create chart
            IChart chart = sheet.Charts.Add();
            
            //Set range
            chart.DataRange = sheet.Range["A1:C2"];
            
            //Set chart to image converter
            application.ChartToImageConverter = new ChartToImageConverter();
            application.ChartToImageConverter.ScalingMode = ScalingMode.Best;
            
            //Save as image
            MemoryStream stream = new MemoryStream();
            chart.SaveAsImage(stream);
            Image image = Image.FromStream(stream);
            image.Save("Output.png");
            
            //Save and Dispose
            workbook.SaveAs("Chart.xlsx");
            workbook.Close();
        }
    }
}
AssemblyVersion

Syncfusion.XlsIO.Base: 17.2460.0.34

See Also