FileDocCategorySizeDatePackage
Thumbnail.javaAPI DocApache Poi 3.0.19134Mon Jan 01 12:39:34 GMT 2007org.apache.poi.hpsf

Thumbnail

public class Thumbnail extends Object

Class to manipulate data in the Clipboard Variant ({@link Variant#VT_CF VT_CF}) format.

author
Drew Varner (Drew.Varner inOrAround sc.edu)
see
SummaryInformation#getThumbnail()
version
$Id: Thumbnail.java 489730 2006-12-22 19:18:16Z bayard $
since
2002-04-29

Fields Summary
public static int
OFFSET_CFTAG

Offset in bytes where the Clipboard Format Tag starts in the byte[] returned by {@link SummaryInformation#getThumbnail()}

public static int
OFFSET_CF

Offset in bytes where the Clipboard Format starts in the byte[] returned by {@link SummaryInformation#getThumbnail()}

This is only valid if the Clipboard Format Tag is {@link #CFTAG_WINDOWS}

public static int
OFFSET_WMFDATA

Offset in bytes where the Windows Metafile (WMF) image data starts in the byte[] returned by {@link SummaryInformation#getThumbnail()}

There is only WMF data at this point in the byte[] if the Clipboard Format Tag is {@link #CFTAG_WINDOWS} and the Clipboard Format is {@link #CF_METAFILEPICT}.

Note: The byte[] that starts at OFFSET_WMFDATA and ends at getThumbnail().length - 1 forms a complete WMF image. It can be saved to disk with a .wmf file type and read using a WMF-capable image viewer.

public static int
CFTAG_WINDOWS

Clipboard Format Tag - Windows clipboard format

A DWORD indicating a built-in Windows clipboard format value

public static int
CFTAG_MACINTOSH

Clipboard Format Tag - Macintosh clipboard format

A DWORD indicating a Macintosh clipboard format value

public static int
CFTAG_FMTID

Clipboard Format Tag - Format ID

A GUID containing a format identifier (FMTID). This is rarely used.

public static int
CFTAG_NODATA

Clipboard Format Tag - No Data

A DWORD indicating No data. This is rarely used.

public static int
CF_METAFILEPICT

Clipboard Format - Windows metafile format. This is the recommended way to store thumbnails in Property Streams.

Note: This is not the same format used in regular WMF images. The clipboard version of this format has an extra clipboard-specific header.

public static int
CF_DIB

Clipboard Format - Device Independent Bitmap

public static int
CF_ENHMETAFILE

Clipboard Format - Enhanced Windows metafile format

public static int
CF_BITMAP

Clipboard Format - Bitmap

Obsolete, see msdn.microsoft.com/library/en-us/dnw98bk/html/clipboardoperations.asp.

private byte[]
thumbnailData

A byte[] to hold a thumbnail image in ({@link Variant#VT_CF VT_CF}) format.

Constructors Summary
public Thumbnail()

Default Constructor. If you use it then one you'll have to add the thumbnail byte[] from {@link SummaryInformation#getThumbnail()} to do any useful manipulations, otherwise you'll get a NullPointerException.




                                     
     
    
        super();
    
public Thumbnail(byte[] thumbnailData)

Creates a Thumbnail instance and initializes with the specified image bytes.

param
thumbnailData The thumbnail data

        this.thumbnailData = thumbnailData;
    
Methods Summary
public longgetClipboardFormat()

Returns an int representing the Clipboard Format

Will throw an exception if the Thumbnail's Clipboard Format Tag is not {@link Thumbnail#CFTAG_WINDOWS CFTAG_WINDOWS}.

Possible return values are:

  • {@link #CF_METAFILEPICT CF_METAFILEPICT}
  • {@link #CF_DIB CF_DIB}
  • {@link #CF_ENHMETAFILE CF_ENHMETAFILE}
  • {@link #CF_BITMAP CF_BITMAP}

return
a flag indicating the Clipboard Format
throws
HPSFException if the Thumbnail isn't CFTAG_WINDOWS

        if (!(getClipboardFormatTag() == CFTAG_WINDOWS))
            throw new HPSFException("Clipboard Format Tag of Thumbnail must " +
                                    "be CFTAG_WINDOWS.");

        return LittleEndian.getUInt(getThumbnail(), OFFSET_CF);
    
public longgetClipboardFormatTag()

Returns an int representing the Clipboard Format Tag

Possible return values are:

  • {@link #CFTAG_WINDOWS CFTAG_WINDOWS}
  • {@link #CFTAG_MACINTOSH CFTAG_MACINTOSH}
  • {@link #CFTAG_FMTID CFTAG_FMTID}
  • {@link #CFTAG_NODATA CFTAG_NODATA}

return
A flag indicating the Clipboard Format Tag

        long clipboardFormatTag = LittleEndian.getUInt(getThumbnail(),
                                                       OFFSET_CFTAG);
        return clipboardFormatTag;
    
public byte[]getThumbnail()

Returns the thumbnail as a byte[] in {@link Variant#VT_CF VT_CF} format.

return
The thumbnail value
see
SummaryInformation#getThumbnail()

        return thumbnailData;
    
public byte[]getThumbnailAsWMF()

Returns the Thumbnail as a byte[] of WMF data if the Thumbnail's Clipboard Format Tag is {@link #CFTAG_WINDOWS CFTAG_WINDOWS} and its Clipboard Format is {@link #CF_METAFILEPICT CF_METAFILEPICT}

This byte[] is in the traditional WMF file, not the clipboard-specific version with special headers.

See http://www.wvware.com/caolan/ora-wmf.html for more information on the WMF image format.

return
A WMF image of the Thumbnail
throws
HPSFException if the Thumbnail isn't CFTAG_WINDOWS and CF_METAFILEPICT

        if (!(getClipboardFormatTag() == CFTAG_WINDOWS))
            throw new HPSFException("Clipboard Format Tag of Thumbnail must " +
                                    "be CFTAG_WINDOWS.");
        if (!(getClipboardFormat() == CF_METAFILEPICT))
            throw new HPSFException("Clipboard Format of Thumbnail must " +
                                    "be CF_METAFILEPICT.");
        else
        {
            byte[] thumbnail = getThumbnail();
            int wmfImageLength = thumbnail.length - OFFSET_WMFDATA;
            byte[] wmfImage = new byte[wmfImageLength];
            System.arraycopy(thumbnail,
                             OFFSET_WMFDATA,
                             wmfImage,
                             0,
                             wmfImageLength);
            return wmfImage;
        }
    
public voidsetThumbnail(byte[] thumbnail)

Sets the Thumbnail's underlying byte[] in {@link Variant#VT_CF VT_CF} format.

param
thumbnail The new thumbnail value
see
SummaryInformation#getThumbnail()

        this.thumbnailData = thumbnail;