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

Free Support Forum - aspose.com


Hi there,

I want to create an image from the chart attached. I’ve been experimenting with Chart.ToImage() and I’m wondering if you can shortcut my testing by telling me which parameters/format/etc will result in the best quality image result.

My goal was to originally insert these charts into a Words document I’m generating but that isn’t fully supported so instead I want to insert an image of the chart. In my testing currently I’m not completely happy with the quality of the image that’s getting generated. I’m using C#.

Thank you.

ImageTest.zip (16.4 KB)

It all depends upon the requirements and scenario where image is being generated hence there is no fixed settings for best results. I tried below sample code with few settings and got proper result. Apparently no issue is observed in the created image and output seems fine. Could you please share what issues are you facing while creating image from the chart? Provide details along with the snapshots and also provide us expected output created by Excel for our reference.

Workbook wb = new Workbook(path + "ExcelChartTest.xlsx");
Chart chart = wb.Worksheets[0].Charts[0];
// Converting chart to image
chart.ToImage(path + "outputChartRendering.emf", System.Drawing.Imaging.ImageFormat.Emf);

// Converting chart to Bitmap
System.Drawing.Bitmap bitmap = chart.ToImage();
bitmap.Save(path + "outputChartRendering.bmp", System.Drawing.Imaging.ImageFormat.Bmp);


//Rendering Chart To Image With Advanced Options
// Create an instance of ImageOrPrintOptions and set a few properties
ImageOrPrintOptions options = new ImageOrPrintOptions()
    VerticalResolution = 300,
    HorizontalResolution = 300,
    SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality,
    TextRenderingHint = TextRenderingHint.ClearTypeGridFit,
    PixelFormat = PixelFormat.Format64bppArgb,

// Convert chart to image with additional settings
chart.ToImage(path + "outputChartRendering.png", options);

// Converting chart to PDF
chart.ToPdf(path + "outputChartRendering.pdf");

Excellent - thank you Ahsan - I was missing a couple of those options (TextRenderingHint and PixelFormat). Adding those made a marked difference in the quality of the PNG generated. I will test some more and reply if I need further guidance.

Thank you for the quick reply!


Good to know that the suggested code segment works for your needs. Please take your time to test the APIs in your scenario/ case. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.