2X faster development
The ultimate WinForms UI toolkit to boost your development speed.
This article explains how to get best quality image in Chart to Image or PDF conversion using WinForms XlsIO. A chart can be converted to image or PDF with two different quality of images and ScalingMode property of IChartToImageConverter interface helps to achieve this in XlsIO. Conversion with `Normal` scaling mode results in image with normal image quality whereas conversion with `Best` scaling mode results in image with best image quality and larger image size. Code snippet to set image quality in Chart to Image or PDF conversion //Set the image quality application.ChartToImageConverter.ScalingMode = ScalingMode.Best;
Note: ScalingMode.Best consumes more memory compared to ScalingMode.Normal.
The following C#/VB complete code snippet shows how to set image quality in Chart to Image or PDF conversion using XlsIO. C# using Syncfusion.ExcelChartToImageConverter; using Syncfusion.XlsIO; using System.Drawing; using System.IO; namespace ImageQuality { class Program { static void Main(string[] args) { using (ExcelEngine excelEngine = new ExcelEngine()) { //Instantiate the excel application object IApplication application = excelEngine.Excel; //Set default version application.DefaultVersion = ExcelVersion.Excel2013; //Initializing the chart to image converter object application.ChartToImageConverter = new ChartToImageConverter(); //Set the image quality application.ChartToImageConverter.ScalingMode = ScalingMode.Normal; //Open existing workbook with data entered Assembly assembly = typeof(Program).GetTypeInfo().Assembly; Stream fileStream = assembly.GetManifestResourceStream("ImageQuality.Sample.xlsx"); IWorkbook workbook = application.Workbooks.Open(fileStream); //The first worksheet object in the worksheets collection is accessed IWorksheet worksheet = workbook.Worksheets[0]; //The first chart object in the charts collection is accessed IChart chart = worksheet.Charts[0]; //Creating the memory stream for chart image MemoryStream stream = new MemoryStream(); //Saving the chart as image chart.SaveAsImage(stream); //Getting the image file from stream Image image = Image.FromStream(stream); //Saving image stream to file image.Save("Output.png"); } } } }
VB Imports System.Drawing Imports System.IO Imports Syncfusion.ExcelChartToImageConverter Imports Syncfusion.XlsIO Namespace ImageQuality Class Program Public Shared Sub Main(ByVal args As String()) Using excelEngine As ExcelEngine = New ExcelEngine() 'Instantiate the excel application object Dim application As IApplication = excelEngine.Excel 'Set default version application.DefaultVersion = ExcelVersion.Excel2013 'Initializing the chart to image converter object application.ChartToImageConverter = New ChartToImageConverter 'Set the image quality application.ChartToImageConverter.ScalingMode = ScalingMode.Best 'Open existing workbook with data entered Dim assembly As Assembly = GetType(Program).GetTypeInfo.Assembly Dim fileStream As Stream = assembly.GetManifestResourceStream("ImageQuality.Sample.xlsx") Dim workbook As IWorkbook = application.Workbooks.Open(fileStream) 'The first worksheet object in the worksheets collection is accessed Dim worksheet As IWorksheet = workbook.Worksheets(0) 'The first chart object in the charts collection is accessed Dim chart As IChart = worksheet.Charts(0) 'Creating the memory stream for chart image Dim stream As MemoryStream = New MemoryStream 'Saving the chart as image chart.SaveAsImage(stream) 'Getting the image file from stream Dim image As Image = Image.FromStream(stream) 'Saving image stream to file image.Save("Output.png") End Using End Sub End Class End Namespace
Conclusion I hope you enjoyed learning about how to get good quality image during chart to image or PDF conversion in C#, VB.NET. You can refer to our WinForms XlsIO’s feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms XlsIO documentation to understand how to present and manipulate data. For current customers, you can check out our WinForms components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our WinForms XlsIO and other WinForms components. If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!
|
2X faster development
The ultimate WinForms UI toolkit to boost your development speed.
This page will automatically be redirected to the sign-in page in 10 seconds.