I am working on a project that involves adding charts to both Word DOCs and PowerPoint PPTs. I implemented the DOC version using code similar to:
…I then went to code the “equivalent” for Slides, and I thought it would be:
MemoryStream imageMs = new MemoryStream();
chart.Save(imageMs, imageFormat);
shape.ImageData.SetImage(imageMs);
…
…However, this caused an exception. The issue appears to be that after the “chart.Save”, the stream is left at the “end”. If I add the line:
MemoryStream imageMs = new MemoryStream();
chart.Save(imageMs, imageFormat);
Aspose.Slides.Picture oPicture = new Picture(oPresentation, imageMs);
oFrame.PictureId = oPresentation.Pictures.Add(oPicture);
…
imageMs.Position = 0;before the “new Picture”, then everything works fine.
So, it appears to be that when chart.Save() is called, the position of the stream is left at the end. When the constructor of Picture is called and it attempts to get the data from the stream, it does not “reset” the stream position, so it fails. Whereas in Words, the “SetImage()” method must reset the stream position.
I don’t know whether this would be considered a bug, and I wasn’t sure whether I should post this to the Slides, Words, or Reports forums, but it seems inconsistent. At least there should be something to document whether the stream position needs to be reset or whether the “consuming” method does it for you.