Free Support Forum -

Loading image from memory stream

We are using Aspose.Word to insert charts from Dundas into Word and have run into some weird things. Basically we are trying to insert the chart from a memorystream, and it works (to some degree) if the chart is saved as jpg, but we get an error if the chart is saved as emf. If we save the chart to a filestream everything works as expected.

I have attached a c# web project illustrating the problem.

Setting chartImageType to Jpeg works when reading from file and memorystream. Setting chartImageType to Emf only works when reading from a file.

I hope you can help, reading from memory is very convenient Wink

I hope will implement something similar in Aspose.Excel. As far as I could see you can only insert an image from file as the moment.

The problem is not in Aspose.Word, but in the way you load the image from the stream. You need to seek to the beginning of the stream before loading the object.

private Stream SaveChartToMemory(ChartImageType chartImageType)
Chart chart = this.CreateChart(chartImageType);
MemoryStream memoryStream = new MemoryStream();
//You need this.
memoryStream.Seek(0, SeekOrigin.Begin);
return memoryStream;

Aspose.Excel supports to load images from stream. Please check