Spire.Presentation is a professional PowerPoint® compatible library that enables developers to create, read, write, modify, convert and Print PowerPoint documents. Get free and professional technical support for Spire.Presentation for .NET, Java, Android, C++, Python.

Mon Mar 23, 2015 4:32 pm

Is there a way to iterate over the images in a Presentation and replace them? I tried this, but it does not work:

Code: Select all
for (int i = 0; i < ppt.Images.Count; i++)
{
   System.Drawing.Image image = ppt.Images[i].Image;
   image = System.Drawing.Image.FromFile(myNewFilename);
}


I think I need to iterate over each shape and check if it has an image in it, but that approach did not work for me either as I couldn't figure out how to check if a shape contains an image.

jhumber
 
Posts: 5
Joined: Mon Mar 16, 2015 9:27 pm

Tue Mar 24, 2015 8:00 am

Hello,

Thanks for your inquiry.
Sorry that at present the Spire.Presentation doesn’t support the feature of replacing image. But you can remove the image, and then append a new image. Please refer to the following codes:
Code: Select all
String image = @"F:\download\image1.jpg";
RectangleF rf = new RectangleF(ppt.Slides[0].Shapes[0].Left, ppt.Slides[0].Shapes[0].Top, ppt.Slides[0].Shapes[0].Width, ppt.Slides[0].Shapes[0].Height);
ppt.Slides[0].Shapes.RemoveAt(1);
ppt.Slides[0].Shapes.AppendEmbedImage(ShapeType.Rectangle, image, rf);
ppt.SaveToFile("result1.pptx", FileFormat.Pptx2010);

If there are any questions, welcome to get it back to us.

Best Regards,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Wed Mar 25, 2015 12:56 am

Betsy wrote:Hello,

Thanks for your inquiry.
Sorry that at present the Spire.Presentation doesn’t support the feature of replacing image. But you can remove the image, and then append a new image. Please refer to the following codes:
Code: Select all
String image = @"F:\download\image1.jpg";
RectangleF rf = new RectangleF(ppt.Slides[0].Shapes[0].Left, ppt.Slides[0].Shapes[0].Top, ppt.Slides[0].Shapes[0].Width, ppt.Slides[0].Shapes[0].Height);
ppt.Slides[0].Shapes.RemoveAt(1);
ppt.Slides[0].Shapes.AppendEmbedImage(ShapeType.Rectangle, image, rf);
ppt.SaveToFile("result1.pptx", FileFormat.Pptx2010);

If there are any questions, welcome to get it back to us.

Best Regards,
Betsy
E-iceblue support team


Thank you, that helps. How can I determine which shapes have images in them? That's the other part I cannot figure out.

jhumber
 
Posts: 5
Joined: Mon Mar 16, 2015 9:27 pm

Wed Mar 25, 2015 6:36 am

Hello,

You can refer to the following codes:
Code: Select all
IShape shape = ppt.Slides[0].Shapes[0];
if (shape is IEmbedImage)
 {
    String image = @"F:\download\image1.jpg";
    RectangleF rff = new RectangleF(ppt.Slides[0].Shapes[0].Left, ppt.Slides[0].Shapes[0].Top, ppt.Slides[0].Shapes[0].Width, ppt.Slides[0].Shapes[0].Height);
    ppt.Slides[0].Shapes.RemoveAt(1);
    ppt.Slides[0].Shapes.AppendEmbedImage(ShapeType.Rectangle, image, rff);
}

If there are any questions, welcome to get it back to us.

Best Regards,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Fri Mar 27, 2015 8:27 am

Hello,

Has your issue been resolved? Could you please give us some feedback at your convenience?

Thanks,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Tue Mar 31, 2015 2:33 pm

Hi Betsy,

Yes, this has been resolved. Thank you for your help.

jhumber
 
Posts: 5
Joined: Mon Mar 16, 2015 9:27 pm

Return to Spire.Presentation