title: How to set a different image for the background of each slide of the powerpoint using JAVA Apache POI?
body: <p>I am trying to create a powerpoint and set a different image as background for each slide of my powerpoint. Unfortunatly, even if I success to change the background of my powerpoint by an image, my background will always be the last image of the loop.</p>
  
  <p>In the code every image is name 'image('i')' with i the number of the image and I want the first image to be the background of the first slide, the second image the background of the second slide and etc...</p>
  
  <p>If someone can help me please.
  Thanks</p>
  
  <pre><code>//Find number of slides to create
  int nbSlide = new File(directoryScreen).listFiles().length;
  //creating a new empty slide show
  XMLSlideShow ppt = new XMLSlideShow();
  XSLFSlideMaster slideMaster = ppt.getSlideMasters().get(0);
  List&lt;XSLFSlideLayout&gt; slides = new ArrayList&lt;XSLFSlideLayout&gt;();
  for(int i=1; i&lt;=nbSlide; i++) 
     XSLFPictureData pd = ppt.addPicture(new 
     File(directoryScreen+"\\image"+i+".png"), PictureType.PNG);
     XSLFSlideLayout slidelayout = slideMaster.getLayout(SlideLayout.BLANK);
     XSLFPictureShape ps = slidelayout.createPicture(pd);
     ps.setAnchor(new Rectangle2D.Double(0, 0, 960, 540));
     slides.add(slidelayout);
  }
  for(int i=0; i&lt;nbSlide; i++) {
     XSLFSlide sl = ppt.createSlide(slides.get(i));
  }
  </code></pre>