Adding Images on Slides

Dear srivani,

Thanks for considering Aspose.Slides

You can add more than one picture on a single slide or you can add the same picture on more than one slide.

I have written a VB.NET code, that reads source images from directory and add one image per slide and add two existing images on last slide.

Hopefully, it is helpful. You can also get the sample images and the output presentation from the attachment on this post.

VB.NET CODE

'Create a new presentation
Dim pres As New Presentation

'Get the first slide added by default
Dim defaultSld As Slide = pres.GetSlideByPosition(1)

Dim imageDir As String = "..\..\..\images"
Dim images() As String = Directory.GetFiles(imageDir)
Dim imageCount As Integer = images.Length

For Each image As String In images
    'Create a picture inside presentation
    Dim pic As Aspose.Slides.Picture
    pic = New Picture(pres, image)

    'Add it in presentation
    Dim picId As Integer
    picId = pres.Pictures.Add(pic)

    'Add a new slide
    Dim newSld As Slide = pres.AddEmptySlide()

    'Add a new picture frame on new slide
    Dim pf As PictureFrame = newSld.Shapes.AddPictureFrame(picId, 100, 100, 5000, 4000)
Next

'Now add two images on last slide
'Take the already added images and don't insert new one
'Don't need to add one more slide, just position the default slide
'as last slide
defaultSld.SlidePosition = pres.Slides.LastSlidePosition
Dim lastSld As Slide = defaultSld

'Add two picture frames on last slide
Dim picId1 As Integer, picId2 As Integer
picId1 = pres.Pictures(0).PictureId
picId2 = pres.Pictures(1).PictureId

lastSld.Shapes.AddPictureFrame(picId1, 100, 100, 5000, 2000)
lastSld.Shapes.AddPictureFrame(picId2, 100, 2010, 5000, 2000)

'Write presentation on disk
pres.Write("c:\\outImages.ppt")

This is the same code in C# as shown above in VB.NET with little modifications.

Basically, the code reads images from a source directory and then inserts one image per slide and for last slide it adds two already inserted images.

I have attached the source images and output presentation of it for you to view.

C#

//Create a new presentation
Presentation pres = new Presentation();

//Get the first slide added by default
Slide defaultSld = pres.GetSlideByPosition(1);

//Path of the directory where images are present
string imageDir = "C:\\Images";

//Get the paths of all images in an array
string[] images = Directory.GetFiles(imageDir);
int imageCount = images.Length;

//Width and height of the pictureframe
//to be used later
int picWidth = pres.SlideSize.Width;
int picHeight = pres.SlideSize.Height;

foreach (string image in images)
{
    //Create a picture inside presentation
    Picture pic = new Picture(pres, image);

    //Add it in presentation
    int picId = pres.Pictures.Add(pic);

    //Add a new slide
    Slide newSld = pres.AddEmptySlide();

    //Add a new picture frame on new slide
    PictureFrame pf = newSld.Shapes.AddPictureFrame(picId, 0, 0, picWidth, picHeight);
}//foreach

//Just for illustration, you can add multiple pictureframes on a single slide
//Lets add existing images on last slide. By existing, I mean the images
//which have already been added as pictures
//You don't need to add one more slide, just position the default slide
//as last slide
defaultSld.SlidePosition = pres.Slides.LastSlidePosition;
Slide lastSld = defaultSld;

//Add two picture frames on last slide
int picId1 = pres.Pictures[0].PictureId;
int picId2 = pres.Pictures[1].PictureId;

lastSld.Shapes.AddPictureFrame(picId1, 0, 0, picWidth, picHeight / 2);
lastSld.Shapes.AddPictureFrame(picId2, 0, picHeight / 2, picWidth, picHeight / 2);

//Write presentation on disk
pres.Write("c:\\outImages.ppt");

Hi ,

How to add image and setOle Object in PPTX file. ,as we do in PPT file

OleObjectFrame oof = slide1.getShapes().addOleObjectFrame(0, 0,

(int) pres.getSlideSize().getX(),

(int) pres.getSlideSize().getY(), "Excel.Sheet.8", b);

Regards

Janakiraman

Hello,

Both features are not available in JAVA version as yet. But in next release you will be able to add image in PPTX presentation. Adding OleObjects in PPTX might take longer time.

In this thread, I explained how to add an image in PPTX presentation. But it is in .NET as mentioned above.

Hi ,

Is it possible to add OleObjects in PPTX using .Net

Regards

Janakiraman

Dear Janakiraman,

No, it is not possible to add OleObjects in PPTX using Aspose.Slides.NET