Category / Section
Is custom resolution supported in PowerPoint slide to image conversion?
1 min read
You can improve the image quality by providing custom image resolution while conversion.
The following code snippet demonstrates how to convert Presentation slides to images with custom image resolution.
C#
//Opens a PowerPoint presentation IPresentation presentation = Presentation.Open("../../Data/SlidesSample.pptx"); //Iterates through the slide collection to convert as image foreach (ISlide slide in presentation.Slides) { //Converts the slide as image Image image = slide.ConvertToImage(Syncfusion.Drawing.ImageType.Bitmap); //Creates a bitmap of specific width and height Bitmap bitmap = new Bitmap((int)((image.Width * 500) / 96.0f), (int)((image.Height * 500) / 96.0f), PixelFormat.Format32bppPArgb); //Sets the resolution bitmap.SetResolution(500, 500); //Gets graphics from the custom size bitmap image Graphics graphics = Graphics.FromImage(bitmap); //Recreate the image from stream using specified width and height graphics.DrawImage(image, new Rectangle(0, 0, bitmap.Width, bitmap.Height)); //Saves the image image.Save("ImageOutput" + Guid.NewGuid().ToString() + ".jpeg"); } //Closes the presentation presentation.Close();
VB.NET
'Opens a PowerPoint presentation Dim presentationDocument As IPresentation = Presentation.Open("../../Data/Test1.pptx") 'Iterates through the slide collection to convert as image For Each slide As ISlide In presentationDocument.Slides 'Converts the slide as image Dim image As Image = slide.ConvertToImage(Syncfusion.Drawing.ImageType.Bitmap) 'Creates a bitmap of specific width and height Dim bitmap As New Bitmap(CInt((image.Width * 500) / 96.0F), CInt((image.Height * 500) / 96.0F), PixelFormat.Format32bppPArgb) 'Sets the resolution bitmap.SetResolution(500, 500) 'Gets graphics from the custom size bitmap image Dim gdiGraphics As Graphics = Graphics.FromImage(bitmap) 'Recreate the image from stream using specified width and height gdiGraphics.DrawImage(image, New Rectangle(0, 0, bitmap.Width, bitmap.Height)) 'Saves the image image.Save("ImageOutput" + Guid.NewGuid().ToString() + ".jpeg") Next 'Closes the presentation presentationDocument.Close()
Sample Link - https://www.syncfusion.com/downloads/support/directtrac/172771/ze/Sample-1665031271