Methods Summary |
---|
public static org.apache.poi.hslf.usermodel.PictureData | create(int type)Create an instance of PictureData by type.
PictureData pict;
switch (type){
case Picture.EMF:
pict = new EMF();
break;
case Picture.WMF:
pict = new WMF();
break;
case Picture.PICT:
pict = new PICT();
break;
case Picture.JPEG:
pict = new JPEG();
break;
case Picture.PNG:
pict = new PNG();
break;
case Picture.DIB:
pict = new DIB();
break;
default:
throw new IllegalArgumentException("Unsupported picture type: " + type);
}
return pict;
|
public static byte[] | getChecksum(byte[] data)Compute 16-byte checksum of this picture using MD5 algorithm.
MessageDigest sha;
try {
sha = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e){
throw new HSLFException(e.getMessage());
}
sha.update(data);
return sha.digest();
|
public abstract byte[] | getData()Returns the binary data of this Picture
|
public byte[] | getHeader()Return 24 byte header which preceeds the actual picture data.
The header consists of 2-byte signature, 2-byte type,
4-byte image size and 16-byte checksum of the image data.
byte[] header = new byte[16 + 8];
LittleEndian.putInt(header, 0, getSignature());
LittleEndian.putInt(header, 4, getRawData().length);
System.arraycopy(rawdata, 0, header, 8, 16);
return header;
|
public int | getOffset()File offset in the 'Pictures' stream
return offset;
|
public byte[] | getRawData()Returns the raw binary data of this Picture excluding the first 8 bytes
which hold image signature and size of the image data.
return rawdata;
|
protected abstract int | getSignature()Blip signature.
|
public int | getSize()Return image size in bytes
return getData().length;
|
public abstract int | getType()Returns type of this picture.
Must be one of the static constants defined in the Picture class.
|
public byte[] | getUID()Returns 16-byte checksum of this picture
byte[] uid = new byte[16];
System.arraycopy(rawdata, 0, uid, 0, uid.length);
return uid;
|
public abstract void | setData(byte[] data)Set picture data
|
public void | setOffset(int offset)Set offset of this picture in the 'Pictures' stream.
We need to set it when a new picture is created.
this.offset = offset;
|
public void | setRawData(byte[] data)
rawdata = data;
|
public void | write(java.io.OutputStream out)Write this picture into OutputStream
byte[] data;
data = new byte[LittleEndian.SHORT_SIZE];
LittleEndian.putUShort(data, 0, getSignature());
out.write(data);
data = new byte[LittleEndian.SHORT_SIZE];
LittleEndian.putUShort(data, 0, getType() + 0xF018);
out.write(data);
byte[] rawdata = getRawData();
data = new byte[LittleEndian.INT_SIZE];
LittleEndian.putInt(data, 0, rawdata.length);
out.write(data);
out.write(rawdata);
|