Adding an Image in PPTX presentation

Below is the code example, which illustrates, how to add an image in PPTX presentation. I have also attached the source presentation, image and output presentation with this post.

C#

//Read the source pptx

PresentationEx pres = new PresentationEx(@"c:\source\source.pptx");

//Access the first slide

SlideEx sld = pres.Slides[0];

//Read the image

Image img = Bitmap.FromFile(@"c:\BlueHills.jpg");

//Add the image in Presentation.Images collection

ImageEx imgEx=pres.Images.AddImage(img);

//Add the pictureframe

sld.Shapes.AddPictureFrame(ShapeTypeEx.Rectangle, 120, 110, 480, 320, imgEx);

//Write the presentation on disk

pres.Write("c:\\source\\output.pptx");

Below is the JAVA code equivalent to above C# code.

//Read the source pptx
PresentationEx pres = new PresentationEx("c:/test/source.pptx");

//Access the first slide
SlideEx sld = pres.getSlides().get(0);

//Read the image
BufferedImage img = ImageIO.read(new File("c:/test/BlueHills.jpg"));

//Add the image in Presentation.Images collection
ImageEx imgEx = pres.getImages().addImage(img);

//Add the pictureframe
sld.getShapes().addPictureFrame(ShapeTypeEx.RECTANGLE, 120, 110, 480, 320, imgEx);

//Write the presentation on disk
pres.write("c:/test/output2.pptx");