How do I add an image to a picture placeholder using Slides for Java?

<span style=“font-size:11.0pt;font-family:“Calibri”,“sans-serif”;
mso-fareast-font-family:“Times New Roman”;mso-bidi-font-family:“Times New Roman”;
mso-ansi-language:EN-GB;mso-fareast-language:EN-US;mso-bidi-language:AR-SA”>Using Aspose Slides for Java, is it possible to interact with a picture placeholder
that has been put on a masterslide?

<span style=“font-size:11.0pt;font-family:“Calibri”,“sans-serif”;
mso-fareast-font-family:“Times New Roman”;mso-bidi-font-family:“Times New Roman”;
mso-ansi-language:EN-GB;mso-fareast-language:EN-US;mso-bidi-language:AR-SA”>Our
client has a PPTX file that contains picture placeholders – they want images to
be added to these placeholders programmatically and formatted in the same way it would be if a user opened the PPTX file in PowerPoint and clicked the button in the middle of the placeholder (which enables the user to browse for an image).
<span style=“font-size:11.0pt;font-family:“Calibri”,“sans-serif”;
mso-fareast-font-family:“Times New Roman”;mso-bidi-font-family:“Times New Roman”;
mso-ansi-language:EN-GB;mso-fareast-language:EN-US;mso-bidi-language:AR-SA”>I have uploaded an example PPTX file, which contains a very simple picture placeholder.
<span style=“font-size:11.0pt;font-family:“Calibri”,“sans-serif”;
mso-fareast-font-family:“Times New Roman”;mso-bidi-font-family:“Times New Roman”;
mso-ansi-language:EN-GB;mso-fareast-language:EN-US;mso-bidi-language:AR-SA”>Thanks,
<span style=“font-size:11.0pt;font-family:“Calibri”,“sans-serif”;
mso-fareast-font-family:“Times New Roman”;mso-bidi-font-family:“Times New Roman”;
mso-ansi-language:EN-GB;mso-fareast-language:EN-US;mso-bidi-language:AR-SA”>Martin

Hi Martin,

I have tried to understand your problem statement and based on my understating you want to add picture in a shape by using Aspose.Slides. Please visit this documentation link to fill shape with picture.

Let me know, If you have any further queries.

Hi,


Thanks for your reply. I did try this approach but I am looking to make use of PowerPoint’s placeholders for the following reasons:
- Using placeholders in PowerPoint the picture is automatically cropped to the size of the placeholder.
- Using placeholders a user can change the layout of a slide (Home->Layout).

You might want to try adding a placeholder yourself to a presentation to see what I mean by ‘placeholder’:
- In PowerPoint, go to the ‘View’ menu.
- Click ‘Master Layout’
- Right click in the left-hand pane and choose ‘insert layout’
- Click ‘Insert Placeholder’ in the top sub-menu and then choose ‘Picture’
- Draw the placeholder shape on the new layout
- Close the ‘master layout’
- On a slide in the presentation, right click on the slide in the left-hand pane and select ‘Layout’ and choose the new layout you just added.
- You should then see a ‘placeholder’ - you can click on the button in the middle to upload a picture.

If Aspose Slides for Java cannot interact with placeholders then I might be able to use the technique you described if I can get the image to be cropped to fit. Is this possible?

Thanks,
Martin

Hi Martin,

I regret to share with you that Aspose.Slides does not support such feature. However You can add image in a placeholder as I shared before.

We are sorry for your inconvenience.

In your example, is it possible to set the properties of the shape so that the image is cropped? If so, could you provide a code example of this?

Thanks,
Martin

Hi Martin,

Please accept my apology for late response. Please use the following code snippet to fill the shape with image. Please also visit the following documentation link.

  1. Adding Picture Frame to Slide
  2. Filling Shapes with Picture
  3. ShapeEx
  4. ShapesEx
  5. ImageEx
  6. PictureEx
//Instantiate PrseetationEx class that represents the PPTX
PresentationEx pptxPresentation = new PresentationEx();
//Get the first slide
SlideEx pptxSlide = pptxPresentation.getSlides().get(0);

//Add autoshape of rectangle type
int shapeIndex = pptxSlide.getShapes().addAutoShape(ShapeTypeEx.RECTANGLE, 0, 0, 1024, 768);
ShapeEx pptxAutoShape = pptxSlide.getShapes().get(shapeIndex);

//Set the fill type to Picture
pptxAutoShape.getFillFormat().setFillType(FillTypeEx.PICTURE);

//Set the picture fill mode
pptxAutoShape.getFillFormat().getPictureFillFormat().setPictureFillMode(PictureFillModeEx.STRETCH);

//Set the picture
BufferedImage image = ImageIO.read(new File(“d:\pptx\Chrysanthemum.jpg”));
ImageEx pptxImage = pptxPresentation.getImages().addImage(image);

pptxAutoShape.getFillFormat().getPictureFillFormat().getPicture().setImage(pptxImage);

//Write the PPTX file to disk
pptxPresentation.save(“d:\pptx\RectShpPicJ.pptx”, SaveFormat.PPTX);
Hope this answers your query. Let me know, If you have any further queries.

Your example STRETCHES the images to fill the shape (as the name of the enum PictureFillModeEx.STRETCH suggests), which is not much use unless the source image is very similar in aspect ratio to the shape.

I want them to be CROPPED to fill the shape.

Please let me know if this is possible, or if my question/issue is still not clear.

Thanks,
Martin

Hi Martin,

I regret to share with you that Aspose.Slide does not support the requested feature. However, I
have logged a new feature request as SLIDESJAVA-32532 in our issue
tracking system to support it. You will be notified via this forum
thread once this feature is available.

We apologize for your inconvenience.

Your example is not adding an image to an existing image place holder. can this be done?

Hi Keivn,


I feel you have launched the same query in a separate thread. I have already shared my response with you here. Please share, if I may help you further in this regard.

Many Thanks,