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

Free Support Forum - aspose.com

Chart ToImage output has blocky font

Hi,


I am trying to copy paste a chart as an image (back into the worksheet) similar to how in Excel you can paste a chart as an image.

I am using the following code:

var workbook = new Workbook(“ChartAsPic.xlsx”);
var sheet = workbook.Worksheets[0];
var chart = workbook.Worksheets[0].Charts[0];

var ms = new MemoryStream();
chart.ToImage(ms, ImageFormat.Png);

sheet.Shapes.AddPicture(23, 10, ms, 100, 100);

workbook.Save(“ChartAsPicOut.xlsx”);

I am not sure if this is the recommended way of doing this, but the resulting image looks ok a part from the fonts being very ‘blocky’.

I have attached the concerned Excel file where you can see the result from Excel’s own ‘paste as image’ implementation.

I have also attached a zoomed-in screenshot to show you what I mean with ‘blocky’ (top is Aspose, bottom is Excel’s own picture).

The ‘blocky’ characters exist for all axes and legends including the chart title.


Am I adding the picture using the wrong method or is this something that will have to be fixed as a bug?

Best regards.

Hi John,

Thanks for your posting and using Aspose.Cells.

Since, it is an image, so if you will zoom it, then text will be shown as distorted like boxes. I have attached the output Excel file generated by your code and did not notice any considerable difference between Excel and Aspose.Cells output. Both looks same even if we zoom them.

Hi,


In the screenshot above I am comparing two images, one from Excel and one from Aspose. Of course they are going to be different from the original chart; but as you can see the Aspose one is clearly very blocky, especially when looking at the chart title (I have attached a screenshot of that as well, with Aspose on the right and the Excel picture on the left).

The output you posted looks different than mine (much better).

I have attached the output I get using the code above. Why would there be such a discrepancy? I am using 8.3.1.4.


Best regards.

Hi John,


Thank you for writing back,

Please set the ImageFormat to Emf while saving chart to image format. It should fix the problem as mentioned in this thread. Please check the following piece of code and its resultant spreadsheet as attached.

C#

var workbook = new Workbook(“D:/temp/ChartAsPic.xlsx”);
var sheet = workbook.Worksheets[0];
var chart = sheet.Charts[0];

var ms = new MemoryStream();
chart.ToImage(ms, ImageFormat.Emf);
chart.ToImage(“D:/output.emf”, ImageFormat.Emf);

sheet.Shapes.AddPicture(23, 10, ms, 100, 100);
workbook.Save(“D:/ChartAsPicOut.xlsx”);

Hi,


Emf is indeed better, thank you.


It is still visibly different from what Excel produces (slightly blockier on the title) but I am assuming that you have no plans on enhancing this?


Best regards.

Hi John,


Thank you for the confirmation on previously provided solution. There is a very slight change in the results of EMF image as compared to the Excel generated image, however, we may not be able to reduce this difference any further in near future.