Picture Frame

Create Picture Frame

Picture frame is also one of the shapes offered by Aspose.Slides for .NET. Adding picture frame to a slide is bit trickier than simple shapes. A picture frame is like a picture in a frame. You can add any desired picture to your slide as a picture frame. Let’s see, how can we do it. This article explains how picture frames can be used in different ways:

  • Adding Simple Picture Frames to Slides.
  • Controlling Picture Frame Formatting.
  • Adding Picture Frame with Relative Scale.

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

  • Create an instance of Presentation class.
  • Obtain the reference of a slide by using its index.
  • 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.
  • Calculate the width and height of the image.
  • 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.
  • Add a picture frame (containing the picture) to the slide.
  • Write the modified presentation as a PPTX file.

The above steps are implemented in the example given below.

Create Picture Frame with Relative Scale

The picture frame that we created in the above section were simple as well as well formatted. We can also control the relative scaling of image added in picture frame as well. In order to control the relative scaling of the image in a picture frame, please follow the steps below:

  • Create an instance of Presentation class.
  • Obtain the reference of a slide by using its index.
  • Add an image to the presentation image collection.
  • Create an IPPImage object by adding an image to the Images collection associated with the Presentation object that will be used to fill the shape.
  • Set the relative width and height of the image in the picture frame.
  • Write the modified presentation as a PPTX file.

The above steps are implemented in the example given below.

Picture Frame Formatting

The picture frame that we created in the above section is simple. We can also control the formatting of a picture frame according to the requirement. There are many formatting settings that can be applied on a picture frame. To control the formatting of a picture frame in a slide, please follow the steps below:

  • Create an instance of Presentation class.
  • Obtain the reference of a slide by using its index.
  • Create an IPPImage object by adding an image to the Images collection associated with the Presentation object that will be used to fill the shape.
  • Calculate the width and height of image.
  • Create a PictureFrame according to the width and height of the image by using the AddPictureFrame method exposed by the IShapes object associated with the referenced slide.
  • Add the picture frame (containing the picture) to the slide.
  • Set the picture frame’s line color.
  • Set the picture frame’s line width.
  • Rotate the picture frame by giving it either a positive or negative value.
  • A positive value rotates it clockwise; a negative value rotates it anti-clockwise.
  • Add the picture frame (containing the picture) to the slide.
  • Write the modified presentation as a PPTX file.

The above steps are implemented in the example given below.

Add StretchOff Property

The Properties StretchOffsetLeft, StretchOffsetTop, StretchOffsetRight and StretchOffsetBottom has been added to IPictureFillFormat interface and PictureFillFormat class respectively. These properties specify a fill rectangle. When stretching of an image is specified, a source rectangle is scaled to fit the specified fill rectangle. Each edge of the fill rectangle is defined by a percentage offset from the corresponding edge of the shape’s bounding box. A positive percentage specifies an inset, while a negative percentage specifies an outset.

  • Create an instance of Presentation class.
  • Obtain the reference of a slide by using its index.
  • Add an AutoShape of Rectangle type.
  • Create Image.
  • Set shape’s fill type.
  • Set shape’s picture fill mode.
  • Add Set image to fill the shape.
  • Specify image offsets from the corresponding edge of the shape’s bounding box
  • Write the modified presentation as a PPTX file.

The above steps are implemented in the example given below.