Spire.Presentation is a professional PowerPoint® compatible library that enables developers to create, read, write, modify, convert and Print PowerPoint documents. Get free and professional technical support for Spire.Presentation for .NET, Java, Android, C++, Python.

Mon Jul 31, 2017 1:46 pm

Hello, we're trying to use spire to save each slide of a ppt as an image, but when using the sample code from the documentation
"Tutorials > Spire.Presentation >Spire.Presentation Program Guide >Conversion" we're getting blurry images. Is there something we're missing that will give us a clearer resolution? We tried taking the scaling off but that made it worse.

Code:

Code: Select all
 static void Main(string[] args)
        {
            int no_images = 0;
            string test_dir = @"C:\Test\Adhoc Images\adhoc_test.pptx";
            string output_dir = @"C:\Test\Adhoc Images\Output\";
            try
            {
                Presentation ppt = new Presentation();

                ppt.LoadFromFile(test_dir, FileFormat.Auto);

                Directory.CreateDirectory(test_dir);
                Directory.CreateDirectory(output_dir);

                no_images = ppt.Slides.Count;
                for (int i = 0; i < ppt.Slides.Count; i++)
                {
                    int img_width = 1075;
                    int img_height = 710;

                    Image img = ppt.Slides[i].SaveAsImage(img_width, img_height);

                    string datetime = DateTime.Now.ToString("yyyyMMddhhmmss");
                    string filename = datetime + "_" + i + "_" + ".png";
                    img.Save(output_dir + filename, ImageFormat.Png);
                }

            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

        }

jdomsky1
 
Posts: 7
Joined: Mon Jul 31, 2017 12:57 pm

Tue Aug 01, 2017 2:20 am

Dear jdomsky1,

Thanks for your inquiry.
Please try to use the SaveAsEMF method, here is sample code for your kind reference.
Code: Select all
            Presentation ppt = new Presentation();
            ppt.LoadFromFile( @"F:\adhoc_test.pptx");
            //traverse the slides of PPT files
            for (int i = 0; i < ppt.Slides.Count; i++)
            {
                //save the slide to Image
                Metafile mf = ppt.Slides[i].SaveAsEMF() as Metafile;
                Image image = ResetResolution(mf, 300);
                String fileName = String.Format("11252-img-{0}.png", i);
                image.Save(fileName, System.Drawing.Imaging.ImageFormat.Png);
            }
        public static Image ResetResolution(Metafile mf, float resolution)
        {
            int width = (int)(mf.Width * resolution / mf.HorizontalResolution);
            int height = (int)(mf.Height * resolution / mf.VerticalResolution);
            Bitmap bmp = new Bitmap(width, height);
            bmp.SetResolution(resolution, resolution);
            using (Graphics g = Graphics.FromImage(bmp))
            {
                g.DrawImage(mf, Point.Empty);
            }
            return bmp;
        }

If there is any question, please let us know.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Wed Aug 02, 2017 8:06 am

Dear jdomsky1,

Did you test the code I provided ?
Did it help you solve your issue ?

Thanks,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Thu Aug 10, 2017 10:12 pm

We are still having issues with certain slides getting jagged lines. I've added code for scaling to a certain size but even when removing this the image quality is still poor. Please let me know what we can do to get this to a higher quality.


Code: Select all
  Presentation ppt = new Presentation();
            ppt.LoadFromFile( @"F:\adhoc_test.pptx");
            //traverse the slides of PPT files
                        int img_width = 1075;
                        int img_height = 710;
                        float resolution = 200;
            for (int i = 0; i < ppt.Slides.Count; i++)
            {
                //save the slide to Image
                Metafile mf = ppt.Slides[i].SaveAsEMF() as Metafile;
                Image image = ResetResolution(mf, resolution );
                image = ResizeImage(image, img_width, img_height);

                String fileName = String.Format("11252-img-{0}.png", i);
                image.Save(fileName, System.Drawing.Imaging.ImageFormat.Png);
            }
        public static Image ResetResolution(Metafile mf, float resolution)
        {
            int width = (int)(mf.Width * resolution / mf.HorizontalResolution);
            int height = (int)(mf.Height * resolution / mf.VerticalResolution);
            Bitmap bmp = new Bitmap(width, height);
            bmp.SetResolution(resolution, resolution);
            using (Graphics g = Graphics.FromImage(bmp))
            {
                g.DrawImage(mf, Point.Empty);
            }
            return bmp;
        }

 public static Image ResizeImage(System.Drawing.Image image, int width, int height)
        {
            var destRect = new Rectangle(0, 0, width, height);
            var destImage = new Bitmap(width, height);

            destImage.SetResolution(image.HorizontalResolution, image.VerticalResolution);

            using (var graphics = Graphics.FromImage(destImage))
            {
                graphics.CompositingMode = CompositingMode.SourceCopy;
                graphics.CompositingQuality = CompositingQuality.HighQuality;
                graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                graphics.SmoothingMode = SmoothingMode.HighQuality;
                graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;

                using (var wrapMode = new ImageAttributes())
                {
                    wrapMode.SetWrapMode(WrapMode.TileFlipXY);
                    graphics.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, wrapMode);
                }
            }

            return destImage;
        }

jdomsky1
 
Posts: 7
Joined: Mon Jul 31, 2017 12:57 pm

Fri Aug 11, 2017 8:11 am

Dear jdomsky1,

Thanks for your feedback.
Since the resolution of the bitmap is related to the size of the bitmap. In order to help you get image with a high quality, we have added a new feature that converting slide to an vectorgraph image with specific size. Once it is done, we will let you know.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Mon Aug 21, 2017 7:24 pm

That's great news! Do you have any idea when this will be available? Very high priority item for us.

Thanks,
Jordan

jdomsky1
 
Posts: 7
Joined: Mon Jul 31, 2017 12:57 pm

Tue Aug 22, 2017 7:08 am

Dear Jordan,

Thanks for your response.
The new feature which could return a Metafile object with specific size has been done, yet we found other issues after testing. We will fix them ASAP and let you know when the hotfix is available. One more thing, there is a way to save the slide to EMF file directly. Maybe it could solve your issue quickly.
Code: Select all
ppt.Slides[i].SaveAsEMF("result.emf");


Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Tue Aug 22, 2017 3:08 pm

That's good news, but we need an ETA as we have a client deliverable we're waiting on for this feature. If we can't get a date we will need to look into alternative options to achieve this.

Please mark this as a very high priority.

jdomsky1
 
Posts: 7
Joined: Mon Jul 31, 2017 12:57 pm

Tue Aug 22, 2017 3:39 pm

Betsy,

I just want to convey the high priority on this ticket. Our largest client cannot produce client reporting in any capacity until the bugs in this library are resolved. This looks very bad on our firm and I am very disappointed in the pace that you are resolving these issues. Simply put we need these issues resolved and pushed to us ASAP or we will lose our client.


thanks,
Chris

csallemi
 
Posts: 2
Joined: Mon May 15, 2017 8:07 pm

Wed Aug 23, 2017 7:37 am

Dear Jordan and Chris,

Thanks for your feedback.
I do understand your situation, and we had given the highest priority to your issue, sorry that I forgot to tell you.
In your document, there's only a picture. At present Spire will handle the picture as a bitmap. You could give it high resolution with big size as I mentioned in first answer, it would get a better quality. Kindly note, you needn't to resize it again like your second code, as the first code I provided has reset the size. Maybe you could give a higher resolution and try again. Yet when you zoom the result image to a certain degree, it must has many jagged lines because it is a bitmap.
And our Dev team is working on the new feature. Sorry that at present we cannot give you an ETA. But I have requested the development team to share any possible ETA. As soon as we have some updates, I would be happy to update you with the status of the correction.
Hope for your understanding.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Thu Aug 24, 2017 5:59 am

Dear Jordan and Chris,

Glad to inform you that the new feature has been implemented, and due to your urgent situation, here is a hotfix for you, please download it and check if it meets your requirement.
Code snippet:
Code: Select all
ppt.Slides[i].SaveAsEMF("result.emf",1075, 710);

And I also attach the screenshot of the result image showing in EMFexplorer on my side. Looking forward to your reply.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Fri Aug 25, 2017 1:44 pm

Great news! Thank you for escalating and we will test today.

jdomsky1
 
Posts: 7
Joined: Mon Jul 31, 2017 12:57 pm

Mon Aug 28, 2017 9:43 am

Dear Jordan,

Thanks for your response.
Looking forward to your feedback after testing.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.Presentation