|
|
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.

|
| Add This
Tutorial To: |
Del.icio.us |
Digg |
Google |
Spurl |
Blink |
Furl |
Simpy |
Y! MyWeb |
|
|