Exporting Pictures from Powerpoint using the API's

S

Simon Turner

Hello Powerpoint experts.

I am having proplems exporting images from powerpoint 2002 using c#
(.Net) The issue im having is that the images are not of there
original size when they are exported.

When i export using the powerpoint saves as dialog the sample image is
760/512 but when i export using api's the image is only 365/246.

The method i am using is as follows:

1.Loop through all shapes in presentation (not shown)
2. If shape is type MsoPicture then i want to export it (not shown)
3. Copy it
4. Create a new blank presentation with one slide on and resize it to
size of shape and paste the shape there.
5. Then export the slide as a jpg.

Here is the C# source code:

//copy picture
myShape.Copy();

//create new presentation set size to size of picture
PowerPoint.Presentation myPres =
pptApp.Presentations.Add(MsoTriState.msoFalse);
myPres.PageSetup.SlideHeight = height;
myPres.PageSetup.SlideWidth = width;

//add a blank slide
PowerPoint.Slide mySlide=
myPres.Slides.Add(1,PowerPoint.PpSlideLayout.ppLayoutText);

//paste the shape and set to top left
PowerPoint.ShapeRange myRange= mySlide.Shapes.Paste();
myRange.Top = 0;
myRange.Left = 0;

//scale the shape to 100% of original size
myRange.LockAspectRatio = MsoTriState.msoTrue;
myRange.ScaleWidth((float)1,MsoTriState.msoTrue,
MsoScaleFrom.msoScaleFromTopLeft);
myRange.ScaleHeight((float)1,MsoTriState.msoTrue,
MsoScaleFrom.msoScaleFromTopLeft);

//export slide and close presentation
mySlide.Export(filename,"JPG",0,0);
myPres.Close();


This produces the results i discribed above. I've looked at all the
resouces i can on this one and still cant get the original size of the
image out, its just weird! Im just wondering if anyone has managed to
do this and if so what am i doing wrong?

Thanks a lot for your help people and all the best.


Simon Turner
 
S

Shyam Pillai

Simon,
Slide export accepts arguments to set the dimension of the exported image.
Check that out. While the mentioned approach is fine, it will fail when you
try to export small images.
PowerPoint 2000 and above VBA supports a hidden member- Export - associated
with a shape object, you can check if the same is available thru C#
interfaces.
 
S

Simon Turner

Hi Steve, the problem is am having is that i have no way of knowing
what the original size of the image that i am trying to export. The
process must be generic and therefore work with all images that could
be in any presentation. I only resized the slide to the size of the
image as i read this was the best method to use on another post.

I need a way of finding out what the original size of the image in the
presentation is and then i could just export to that size. As a lot
of images in presentations are scaled to a % of there original size, i
need to scale them back up to 100%.

Any ideas anyone, i will post the code once i get it to work. Thanks
guys.

Simon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top