Home Java Poi Change Background Picture of Slide Using Java



Change Background Picture of Slide Using Java
Posted on: March 14, 2008 at 12:00 AM
In this example we are going to create a slide then change background picture of the slide.

Change Background Picture of Slide Using Java  

     


In this example we are going to create a slide then change background picture of the slide.

In this example we are creating a slide. In this slide we are inserting a picture to set this picture as background. To set picture as background of slide we are using setPictureData(nameofpicture ) method. We are setting the  pattern type of the picture. To set the pattern we are using setFillType(filltype) method. 

addPicture(byte[] pictureData,int format):
This method is used to add a picture to the workbook. The return type of this method is int. The two parameters are passed into this method. The first one is pictureData and second one is format .The pictureData is byte form of the picture. In this example we are using Picture.PNG as format.

setPictureData(byte[] pictureData):
This method is used to set the picture. Here picture data is name of picture in byte format.

 The code of the program is given below:
import org.apache.poi.hslf.HSLFSlideShow;
import org.apache.poi.hslf.model.Slide;
import org.apache.poi.hslf.usermodel.*;
import org.apache.poi.hslf.usermodel.SlideShow;
import org.apache.poi.hslf.model.*;
import java.io.*;
import java.awt.Color;
import org.apache.poi.hslf.model.TextBox;
class slideBackgroundShap
{
  public static void main(String a[])
  {
  try
  {  
  SlideShow slideShow = new SlideShow();
  Slide slide = slideShow.createSlide();
  slide.setFollowMasterBackground(false);
  Fill fill = slide.getBackground().getFill();
  int id = slideShow.addPicture(new File
(
"1.png"), Picture.PNG);
  fill.setFillType(Fill.FILL_PATTERN);
  fill.setPictureData(id);
  FileOutputStream out = new FileOutputStream
(
"slideBackground.ppt");
  slideShow.write(out);
  out.close()
  }catch(Exception e){}
  }}

The output of the program is given below:

Download this example.

Related Tags for Change Background Picture of Slide Using Java:
cidedatainsertmethodbackgroundtypepatternnamechangeusingthisidsetcreateexamplepicturetoroundexampiceilslidebackfilllihangpeinasmpimeackedacreatingxaxampsfpicatkishallmplgoeaartfrtsettingslittssthatipleplndo


More Tutorials from this section

Ask Questions?    Discuss: Change Background Picture of Slide Using Java  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.