We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

chart.ToImage: Chart from excel to pptx creating a poor quality image

Based on your examples, I have the following code(fyi: this is a condensed version) to put some charts from a spreadsheet to a presentation(pptx).

This is producing a poor quality image in the presentation. It particularly shows on a pie chart with jagged edges.

I am using 4.1 version of aspose.slides. Is there a way i can set the quality of the image? Please suggest a better solution.

c.ToImage((Stream)strm, ImageFormat.Png);

imgChart = System.Drawing.Bitmap.FromStream(strm);

byte[] chartOleData = new byte[wbStream.Length];

strm.Position = 0;

strm.Read(chartOleData, 0, chartOleData.Length);

Aspose.Slides.Pptx.OleObjectFrameEx oof = null;

oof = sld.Shapes.AddOleObjectFrame(x, 35, oleWidth, oleHeight, "Excel.Sheet.12", chartOleData);

oof.Image = pres.Images.AddImage((System.Drawing.Image)imgChart);

Hi George,

Thanks for considering Aspose.Slides.

I have observed the code snippet shared by you. In order to investigate the issue, please share the source chart and code snippet. Please also share which version of Aspose.Slides for .NET and Aspose.Cells for .NET you are using.

Thanks and Regards,

Attached is the chart

As you've already noticed, the code snippet is in my previous email.

I am using 4.1 version of Aspose.Slides and 4.9 version of Aspose.Cells

Please let me know if you need anything else

Hi George,

I have consulted Aspose.Cells team. Actually, you need to set the OLE frame size with reference to chart size. This will improve the quality to some extent as well. We have modified the code snippet shared by in a try to yield some better image quality. Please use the code snippet given below. The code contain the scale parameter that actually sets the value for how much times the chart be scaled in the PPT as compared to original chart size.

PresentationEx pres = new PresentationEx();

pres.Slides.AddEmptySlide(pres.LayoutSlides[0]);

SlideEx Slide = pres.Slides[0];

WorkbookDesigner workbookDesigner = new WorkbookDesigner();

workbookDesigner.Workbook .Open ("D:\\ppt\\chart.xls");

Worksheet worksheet = workbookDesigner.Workbook.Worksheets[0];

Aspose.Cells.Chart chart = worksheet.Charts[0];

MemoryStream wbStream = workbookDesigner.Workbook.SaveToStream();

MemoryStream strm = new MemoryStream();

chart.ToImage((Stream)strm, ImageFormat.Emf);

System.Drawing.Image imgChart = System.Drawing.Bitmap.FromStream(strm);

byte[] chartOleData = new byte[wbStream.Length];

strm.Position = 0;

strm.Read(chartOleData, 0, chartOleData.Length);

Aspose.Slides.Pptx.OleObjectFrameEx oof = null;

int scaleParameter = 1;

int oleWidth = scaleParameter * chart.ChartObject.Width;

int oleHeight = scaleParameter * chart.ChartObject.Height;

oof = Slide.Shapes.AddOleObjectFrame(20, 35, oleWidth, oleHeight, "Excel.Sheet.12", chartOleData);

oof.Image = pres.Images.AddImage((System.Drawing.Image)imgChart);

pres.Write(@"d:\Chart.pptx");

Thanks and Regards,

I tried scaling the picture as suggested. It did not help.

The fact that the original image itself is exported in poor quality wasnt changed by scaling the picture.

Is that all we could do with aspose?

Isnt there a paste special of some sort that gives more flexibility? In powerpoint when you manually paste special the charts from excel it gives different options. Of which bitmap is the worst one can pick.

Bitmap seems to be the default for chart.ToImage() in Aspose.

In the code snippet, it seems to me that I am using .png format. But none of the variations seem to change the quality very much.

Dear George,

I regret to inform you that the solution shared solution has be devised in consultation with Aspose.Cells team. Unfortunately, this is what is currently supported by Aspose.Slides. Unfortunately, there is no flexibility feature like paste special or some other one currently supported with Aspose.Slides.

We are extremely, sorry for your inconvenience,