Picturepublic class Picture extends SimpleShape Represents a picture in a PowerPoint document. |
Fields Summary |
---|
public static final int | EMFWindows Enhanced Metafile (EMF) | public static final int | WMFWindows Metafile (WMF) | public static final int | PICTMacintosh PICT | public static final int | JPEGJPEG | public static final int | PNGPNG | public static final byte | DIBWindows DIB (BMP) |
Constructors Summary |
---|
public Picture(int idx)Create a new Picture
super(null, null);
_escherContainer = createSpContainer(idx);
| protected Picture(EscherContainerRecord escherRecord, Shape parent)Create a Picture object
super(escherRecord, parent);
|
Methods Summary |
---|
protected void | afterInsert(org.apache.poi.hslf.model.Sheet sh)By default set the orininal image size
java.awt.Rectangle anchor = getAnchor();
if (anchor.equals(new java.awt.Rectangle())){
setDefaultSize();
}
| protected org.apache.poi.ddf.EscherContainerRecord | createSpContainer(int idx)Create a new Picture and populate the inital structure of the EscherSp record which holds information about this picture.
EscherContainerRecord spContainer = super.createSpContainer(false);
spContainer.setOptions((short)15);
EscherSpRecord spRecord = spContainer.getChildById(EscherSpRecord.RECORD_ID);
spRecord.setOptions((short)((ShapeTypes.PictureFrame << 4) | 0x2));
//set default properties for a picture
EscherOptRecord opt = (EscherOptRecord)getEscherChild(spContainer, EscherOptRecord.RECORD_ID);
setEscherProperty(opt, EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 8388736);
//another weird feature of powerpoint: for picture id we must add 0x4000.
setEscherProperty(opt, (short)(EscherProperties.BLIP__BLIPTODISPLAY + 0x4000), idx);
return spContainer;
| public org.apache.poi.hslf.usermodel.PictureData | getPictureData()Returns the picture data for this picture.
SlideShow ppt = getSheet().getSlideShow();
PictureData[] pict = ppt.getPictureData();
Document doc = ppt.getDocumentRecord();
EscherContainerRecord dggContainer = doc.getPPDrawingGroup().getDggContainer();
EscherContainerRecord bstore = (EscherContainerRecord)Shape.getEscherChild(dggContainer, EscherContainerRecord.BSTORE_CONTAINER);
List lst = bstore.getChildRecords();
int idx = getPictureIndex();
if (idx == 0){
logger.log(POILogger.ERROR, "no reference to picture data found ");
} else {
EscherBSERecord bse = (EscherBSERecord)lst.get(idx-1);
for ( int i = 0; i < pict.length; i++ ) {
if (pict[i].getOffset() == bse.getOffset()){
return pict[i];
}
}
logger.log(POILogger.ERROR, "no picture found for our BSE offset " + bse.getOffset());
}
return null;
| public int | getPictureIndex()Returns index associated with this picture.
Index starts with 1 and points to a EscherBSE record which
holds information about this picture.
EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.BLIP__BLIPTODISPLAY + 0x4000);
return prop == null ? 0 : prop.getPropertyValue();
| public void | setDefaultSize()Resize this picture to the default size.
For PNG and JPEG resizes the image to 100%,
for other types sets the default size of 200x200 pixels.
PictureData pict = getPictureData();
if (pict instanceof Bitmap){
BufferedImage img = null;
try {
img = ImageIO.read(new ByteArrayInputStream(pict.getData()));
}
catch (IOException e){}
catch (NegativeArraySizeException ne) {}
if(img != null) {
// Valid image, set anchor from it
setAnchor(new java.awt.Rectangle(0, 0, img.getWidth()*POINT_DPI/PIXEL_DPI, img.getHeight()*POINT_DPI/PIXEL_DPI));
} else {
// Invalid image, go with the default metafile size
setAnchor(new java.awt.Rectangle(0, 0, 200, 200));
}
} else {
//default size of a metafile picture is 200x200
setAnchor(new java.awt.Rectangle(50, 50, 200, 200));
}
|
|