I Have a aspose.cells charts that I can save an image successfully like this;
string ChartPathName = path + “piechart.png”;
pieChart.ToImage(ChartPathName);
Now I want to save it to a stream instead of an image. How can I do that?
Thanks for your query.
Aspose.Cells for .NET also supports to save/render the chart to image streams, there are relevant overloaded versions for Chart.ToImage() method. See the following sample code for your reference.
e.g.
Sample code:
var workBook = new Workbook("e:\\test2\\Test.xlsx");
var worksheet = workBook.Worksheets[0];
var chart = worksheet.Charts[0];
using (MemoryStream ms = new MemoryStream())
{
ImageOrPrintOptions options = new ImageOrPrintOptions
{
ImageType = Aspose.Cells.Drawing.ImageType.Png,
VerticalResolution = 300,
HorizontalResolution = 300,
Quality = 100
};
chart.ToImage(ms, options);
// physically save the image file to disk/filepath from streams if you want.
//File.WriteAllBytes("e:\\test2\\chartimage1.png", ms.ToArray());
Hope, this helps a bit.
1 Like
Thanks. This has worked for me
Good to know that the suggested code segment works for your needs. In the event of further queries or issue, feel free to write us back.
1 Like