zhao
2021-07-02 081df17b8cc4a6e7e4f4e1e1887f24810e3ec2f9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/* ====================================================================
   Copyright 2002-2004   Apache Software Foundation
 
   Licensed Under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at
 
       http://www.apache.org/licenses/LICENSE-2.0
 
   Unless required by applicable law or agreed to in writing, software
   distributed Under the License is distributed on an "AS Is" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations Under the License.
==================================================================== */
 
 
namespace HH.WMS.Utils.NPOI.HSSF.UserModel
{
    using System;
    using HH.WMS.Utils.NPOI.DDF;
    using HH.WMS.Utils.NPOI.SS.UserModel;
 
    /// <summary>
    /// Represents binary data stored in the file.  Eg. A GIF, JPEG etc...
    /// @author Daniel Noll
    /// </summary>
    public class HSSFPictureData : IPictureData
    {
        // MSOBI constants for various formats.
        public const short MSOBI_WMF = 0x2160;
        public const short MSOBI_EMF = 0x3D40;
        public const short MSOBI_PICT = 0x5420;
        public const short MSOBI_PNG = 0x6E00;
        public const short MSOBI_JPEG = 0x46A0;
        public const short MSOBI_DIB = 0x7A80;
        // Mask of the bits in the options used to store the image format.
        public static short FORMAT_MASK = unchecked((short)0xFFF0);
 
        /**
         * Underlying escher blip record containing the bitmap data.
         */
        private EscherBlipRecord blip;
 
        /// <summary>
        /// Constructs a picture object.
        /// </summary>
        /// <param name="blip">the underlying blip record containing the bitmap data.</param>
        public HSSFPictureData(EscherBlipRecord blip)
        {
            this.blip = blip;
        }
 
        /// <summary>
        /// Gets the picture data.
        /// </summary>
        /// <value>the picture data.</value>
        public byte[] Data
        {
            get { return blip.PictureData; }
        }
        /// <summary>
        /// gets format of the picture.
        /// </summary>
        /// <value>The format.</value>
        public int Format
        {
            get
            {
                return blip.RecordId - unchecked((short)0xF018);
            }
        }
        /// <summary>
        /// Suggests a file extension for this image.
        /// </summary>
        /// <returns>the file extension.</returns>
        public String SuggestFileExtension()
        {
            switch (blip.RecordId)
            {
                case EscherMetafileBlip.RECORD_ID_WMF:
                    return "wmf";
                case EscherMetafileBlip.RECORD_ID_EMF:
                    return "emf";
                case EscherMetafileBlip.RECORD_ID_PICT:
                    return "pict";
                case EscherBitmapBlip.RECORD_ID_PNG:
                    return "png";
                case EscherBitmapBlip.RECORD_ID_JPEG:
                    return "jpeg";
                case EscherBitmapBlip.RECORD_ID_DIB:
                    return "dib";
                default:
                    return "";
            }
        }
        /**
     * Returns the mime type for the image
     */
        public String MimeType
        {
            get
            {
                switch (blip.RecordId)
                {
                    case EscherMetafileBlip.RECORD_ID_WMF:
                        return "image/x-wmf";
                    case EscherMetafileBlip.RECORD_ID_EMF:
                        return "image/x-emf";
                    case EscherMetafileBlip.RECORD_ID_PICT:
                        return "image/x-pict";
                    case EscherBitmapBlip.RECORD_ID_PNG:
                        return "image/png";
                    case EscherBitmapBlip.RECORD_ID_JPEG:
                        return "image/jpeg";
                    case EscherBitmapBlip.RECORD_ID_DIB:
                        return "image/bmp";
                    default:
                        return "image/unknown";
                }
            }
        }
    }
}