Exporting Pictures from Powerpoint using the API's

  • Thread starter Thread starter Simon Turner
  • Start date Start date
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
 
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.
 
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.

The export happens at a fixed DPI that varies by PPT version. Figure 72dpi for
yours, so if the image is scaled onto a full 10" slide, you'll get
720xwhatever. By shrinking the slide size to match the image size, you're also
decreasing the number of exported pixels.

But rather than save as JPG, have a look at the .Slide.Export method. That
lets you specify the number of pixels you want regardless of the slide size.


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

--
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
Featured Presenter, PowerPoint Live 2004
October 10-13, San Diego, CA www.PowerPointLive.com
================================================
 
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
 
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%.

This will return the picture to the size it was imported at (ie, that
PowerPoint decided should be its size):

' Rescale the picture to its "natural" slze
With oPicture
.Scaleheight 1, msoTrue
.Scalewidth 2, msoTrue
End with

That works for most image types but may not give you reliable sizes for, say,
TIFFs that carry their own sizing info internally.

The size that PPT imports the image at will vary depending on PPT version, so
it pays to do some tests in the version you're working with.

--
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
Featured Presenter, PowerPoint Live 2004
October 10-13, San Diego, CA www.PowerPointLive.com
================================================
 
Back
Top