FileDocCategorySizeDatePackage
PictureData.javaAPI DocApache Poi 3.0.16117Thu May 31 18:45:28 BST 2007org.apache.poi.hslf.usermodel

PictureData

public abstract class PictureData extends Object
A class that represents image data contained in a slide show.
author
Yegor Kozlov

Fields Summary
protected static final int
CHECKSUM_SIZE
Size of the image checksum calculated using MD5 algorithm.
private byte[]
rawdata
Binary data of the picture
protected int
offset
The offset to the picture in the stream
Constructors Summary
Methods Summary
public static org.apache.poi.hslf.usermodel.PictureDatacreate(int type)
Create an instance of PictureData by type.

param
type type of the picture data. Must be one of the static constants defined in the Picture class.
return
concrete instance of PictureData

        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

return
picture data

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.

return
the 24 byte header which preceeds the actual picture 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 intgetOffset()
File offset in the 'Pictures' stream

return
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
picture data


                               
       

                   
       

             
          

           
       

                                   
      
        return rawdata;
    
protected abstract intgetSignature()
Blip signature.

public intgetSize()
Return image size in bytes

return
the size of the picture in bytes
deprecated
Use getData().length instead.

        return getData().length;
    
public abstract intgetType()
Returns type of this picture. Must be one of the static constants defined in the Picture class.

return
type of this picture.

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 voidsetData(byte[] data)
Set picture data

public voidsetOffset(int offset)
Set offset of this picture in the 'Pictures' stream. We need to set it when a new picture is created.

param
offset in the 'Pictures' stream

        this.offset = offset;
    
public voidsetRawData(byte[] data)

        rawdata = data;
    
public voidwrite(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);