Images using POI

Images using POI

Previous Home Next

 

In this page of the example we are going try to create a slide after that change background picture of those slide. In this program we are going to create a slide. In this slide we are set the background in the slide by inserting the picture. To set the picture as background in slide we are using setPictureData(nameofpicture ) method. We are setting the pattern type of the picture. To set the pattern we are usingsetFillType(filltype) method.


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

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


 
package r4r;
import java.io.*;
import java.awt.Color;
import org.apache.poi.hslf.model.TextBox;
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.*;
public class setgbpicture {
	 public static void main(String a[])
	  {
	  try
	  {  
	  SlideShow slideShow = new SlideShow();
	  Slide slide1 = slideShow.createSlide();
	  slide1.setFollowMasterBackground(false);
	  Fill fill = slide1.getBackground().getFill();
	  int d = slideShow.addPicture(new File
	("1.png"), Picture.PNG);
	  fill.setFillType(Fill.FILL_PATTERN);
	  fill.setPictureData(d);
	  FileOutputStream out = new FileOutputStream
	("Backgroundpresentation.ppt");
	  slideShow.write(out);
	  out.close(); 
	  }catch(Exception e){}
	  }
}


Previous Home Next