01: /* ====================================================================
02: Copyright 2002-2004 Apache Software Foundation
03:
04: Licensed under the Apache License, Version 2.0 (the "License");
05: you may not use this file except in compliance with the License.
06: You may obtain a copy of the License at
07:
08: http://www.apache.org/licenses/LICENSE-2.0
09:
10: Unless required by applicable law or agreed to in writing, software
11: distributed under the License is distributed on an "AS IS" BASIS,
12: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: See the License for the specific language governing permissions and
14: limitations under the License.
15: ==================================================================== */
16:
17: package org.apache.poi.hssf.usermodel;
18:
19: import org.apache.poi.ddf.EscherBitmapBlip;
20: import org.apache.poi.ddf.EscherBlipRecord;
21:
22: /**
23: * Represents binary data stored in the file. Eg. A GIF, JPEG etc...
24: *
25: * @author Daniel Noll
26: */
27: public class HSSFPictureData {
28: // MSOBI constants for various formats.
29: public static final short MSOBI_WMF = 0x2160;
30: public static final short MSOBI_EMF = 0x3D40;
31: public static final short MSOBI_PICT = 0x5420;
32: public static final short MSOBI_PNG = 0x6E00;
33: public static final short MSOBI_JPEG = 0x46A0;
34: public static final short MSOBI_DIB = 0x7A80;
35: // Mask of the bits in the options used to store the image format.
36: public static final short FORMAT_MASK = (short) 0xFFF0;
37:
38: /**
39: * Underlying escher blip record containing the bitmap data.
40: */
41: private EscherBlipRecord blip;
42:
43: /**
44: * Constructs a picture object.
45: *
46: * @param blip the underlying blip record containing the bitmap data.
47: */
48: HSSFPictureData(EscherBlipRecord blip) {
49: this .blip = blip;
50: }
51:
52: /**
53: * Gets the picture data.
54: *
55: * @return the picture data.
56: */
57: public byte[] getData() {
58: return blip.getPicturedata();
59: }
60:
61: /**
62: * Suggests a file extension for this image.
63: *
64: * @return the file extension.
65: */
66: public String suggestFileExtension() {
67: switch (blip.getOptions() & FORMAT_MASK) {
68: case MSOBI_WMF:
69: return "wmf";
70: case MSOBI_EMF:
71: return "emf";
72: case MSOBI_PICT:
73: return "pict";
74: case MSOBI_PNG:
75: return "png";
76: case MSOBI_JPEG:
77: return "jpeg";
78: case MSOBI_DIB:
79: return "dib";
80: default:
81: return "";
82: }
83: }
84: }
|