Add Picture Frame to Presentation
Below is the code for adding picture in VSTO presentation:
string ImageFilePath="AddPicture.jpg"; Slide slide = Application.ActivePresentation.Slides; slide.Shapes.AddPicture(ImageFilePath, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoCTrue, 0, 0);
To add a simple picture frame to your slide, please follow the steps below:
- Create an instance of the 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.
string ImageFilePath = "AddPicture.jpg"; //Instantiate Prseetation class that represents the PPTX Presentation pres = new Presentation(); //Get the first slide ISlide sld = pres.Slides; //Instantiate the ImageEx class Image img = (Image)new Bitmap(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
- [Codeplex](https://asposevsto.codeplex.com/SourceControl/latest#Aspose.Slides Vs VSTO Slides/Add Picture Frame/)