Link to home
Start Free TrialLog in
Avatar of williamzNet
williamzNet

asked on

Is It Possible to Create an Image of a PowerPoint Slide in Visual Basic 2010?

Hi,

I am trying to loop through all the slides in a presentation and convert them into jpeg images in a PowerPoint (2007) add-in written in Visual Basic 2010.

However, while I can take screenshots using:

 Public Function getScreenShot() As Byte()

            Dim dblScaleFactor As Double
            Dim intNewHeight As Integer
            Dim intNewWidth As Integer
            Dim imgResized As Bitmap
            Dim img As Image
            Dim ms As New MemoryStream()

            Dim picBytes As Byte()

            img = New Bitmap(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height)


            Dim g As Graphics = Graphics.FromImage(img)
            g.CopyFromScreen(0, 0, 0, 0, img.Size)
            g.Dispose()

            dblScaleFactor = 600 / img.Width
            intNewHeight = CInt(dblScaleFactor * img.Height)
            intNewWidth = CInt(dblScaleFactor * img.Width)

            imgResized = New Bitmap(intNewWidth, intNewHeight)

            g = Graphics.FromImage(imgResized)
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
            g.DrawImage(img, New Rectangle(0, 0, intNewWidth, intNewHeight), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel)
            g.Dispose()

            imgResized.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)

            picBytes = ms.ToArray()

            Return picBytes

        End Function

Open in new window


This takes way too long.  I can also get the images exported to disk and then read them back into memory, but this is really inefficiency as well.

Searching  around I found this code that suggests you can paste a slide image into another slide:

ActivePresentation.Slides(1).Copy
ActivePresentation.Slides(2).Shapes.PasteSpecial ppPasteJPG

Open in new window


But I cannot work out how to convert a shape into a Graphics object.

Help would be greatly appreciated!

Dave
Avatar of BuggyCoder
BuggyCoder
Flag of India image

Avatar of Éric Moreau
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of williamzNet
williamzNet

ASKER

Hi Buggy Coder,

Sorry - I am doing that already.  I would like to avoid having to save to disk...

Thanks for the suggestion though.

:)
Hi Emoreau,

Thanks for the suggestion, but I need to be able to copy and work with the resulting slide images in an add-in I am writing.

Thanks for the suggestion though.

:)
Hi Code Cruiser, thanks for the suggestion - will adopt it if there isn't a way of avoiding the writing to disk bit.

After having the question open for a while, no one has suggested a way of doing it by copying, so I am beginning to think it's not possible.

A shame, as I am pretty sure that one can get the slide into the clipboard, but I have no idea how to paste special when I am not pasting into a document.

Going to leave the question open for a couple of days more in case there is a way...

Cheers,

Dave
It appears that it is not possible to copy and then retrieve the data as images from the clipboard...