Hello,
I am trying to copy a picture from one presentation to another. I have a presentation with just one image in it (PresentationImage.ppt) that I am trying to copy. After I open the written presentation the wrong image appears in the upper left hand corner. The following is the code I am using:
Presentation imagePres = new Presentation(projectPath + “\PresentationImage.ppt”);
Aspose.Slides.Picture pic = imagePres.Pictures[0];
int picID = newPres.Pictures.Add(pic);
titleSlide.Shapes.AddPictureFrame(picID, 0, 0, 300, 300);
The following works for importing an image but I would rather copy the image from an existing presentation:
Aspose.Slides.Picture pic = new Aspose.Slides.Picture(newPres, projectPath + “\PresentationImage.jpg”);
int picID = newPres.Pictures.Add(pic);
titleSlide.Shapes.AddPictureFrame(picID, 0, 0, 300, 300);
Is there something else I need to do before copying the image from the presentation?
Thank you
Hi,
You should first write a Picture to stream using Picture.Write method. Then you should create a new picture from that stream and adds into the target presentation’s Pictures collection and gets its picture id. Finally you should add a picture frame with new picture id you got in the previous step.
e.g
Picture sourcePic = sourcePres.Pictures[0];
//Write it to stream
MemoryStream ms = new MemoryStream();
sourcePic.Write(ms);
ms.Position = 0;
//Create target picture and add it to target presentation
Picture targetPic = new Picture(targetPres, ms);
int picID = targetPres.Pictures.Add(pic);
//Add a picture frame to target slide
targetSlide.Shapes.AddPictureFrame(picID, 0, 0, 300, 300);
Thank you very much. That worked great.