Add Picture Frame to Presentation

VSTO

Below is the code for adding picture in VSTO presentation:


  string ImageFilePath="AddPicture.jpg";

 Slide slide = Application.ActivePresentation.Slides[1];

 slide.Shapes.AddPicture(ImageFilePath, Microsoft.Office.Core.MsoTriState.msoFalse,

 Microsoft.Office.Core.MsoTriState.msoCTrue, 0, 0);

Aspose.Slides

To add a simple picture frame to your slide, please follow the steps below:

  1. Create an instance of the Presentation class.
  2. Obtain the reference of a slide by using its index.
  3. Create an Image object by adding an image to the Images collection associated with the Presentation object that will be used to fill the Shape.
  4. Calculate the width and height of the image.
  5. Create a PictureFrame according to the width and height of the image by using the AddPictureFrame method exposed by the Shapes object associated with the referenced slide.
  6. Add a picture frame (containing the picture) to the slide.
  7. Write the modified presentation as a PPTX file.

The above steps are implemented in the example given below.


   string ImageFilePath = "AddPicture.jpg";

  //Instantiate Prseetation class that represents the PPTX

  Presentation pres = new Presentation();

  //Get the first slide

  ISlide sld = pres.Slides[0];

  //Instantiate the ImageEx class

  using IImage img = Images.FromFile(ImageFilePath);

  IPPImage imgx = pres.Images.AddImage(img);

  //Add Picture Frame with height and width equivalent of Picture

  sld.Shapes.AddPictureFrame(ShapeType.Rectangle, 50, 150, imgx.Width, imgx.Height, imgx);

Download Running Code

Download Sample Code