Ejemplo n.º 1
0
        /// <summary>
        /// Constructor initialized with the bitmap header info
        /// </summary>
        /// <param name="headerInfo">Bitmap header info</param>
        public FileHeader(Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("headerInfo");
            }

            byte[] fileHeader = new byte[18];
            if (stream.Read(fileHeader, 0, fileHeader.Length) < fileHeader.Length)
            {
                throw new InvalidOperationException("Unable to read bitmap file header, less than 18bytes read.");
            }

            Type         = (HeaderField)BitConverter.ToUInt16(fileHeader, 0);
            Size         = BitConverter.ToUInt32(fileHeader, 2);
            Reserved     = BitConverter.ToUInt32(fileHeader, 6);
            BitmapOffset = BitConverter.ToUInt32(fileHeader, 10);
            HeaderSize   = (HeaderType)BitConverter.ToUInt32(fileHeader, 14);

            switch (HeaderSize)
            {
            case HeaderType.BITMAPCOREHEADER:
                _bitmapCoreHeader = new BitmapCoreHeader(stream);
                break;

            case HeaderType.BITMAPINFOHEADER:
            case HeaderType.BITMAPCOREHEADER2:
            case HeaderType.BITMAPV2INFOHEADER:
            case HeaderType.BITMAPV3INFOHEADER:
            case HeaderType.BITMAPV4HEADER:
            case HeaderType.BITMAPV5HEADER:
                BitmapInfoHeader infoHeader = new BitmapInfoHeader(stream);
                _bitmapCoreHeader = infoHeader;
                if (infoHeader.CompressionType == CompressionType.BI_BITFIELDS ||
                    infoHeader.CompressionType == CompressionType.BI_ALPHABITFIELDS)
                {
                    BitMask = new BitMask(HeaderSize, infoHeader.CompressionType, stream);
                }

                break;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Constructor initialized with the bitmap header info
        /// </summary>
        /// <param name="headerInfo">Bitmap header info</param>
        public FileHeader(Stream stream)
        {
            if(stream == null)
                throw new ArgumentNullException("headerInfo");

            byte[] fileHeader = new byte[18];
            if(stream.Read(fileHeader, 0, fileHeader.Length) < fileHeader.Length)
                throw new InvalidOperationException("Unable to read bitmap file header, less than 18bytes read.");

            Type = (HeaderField)BitConverter.ToUInt16(fileHeader, 0);
            Size = BitConverter.ToUInt32(fileHeader, 2);
            Reserved = BitConverter.ToUInt32(fileHeader, 6);
            BitmapOffset = BitConverter.ToUInt32(fileHeader, 10);
            HeaderSize = (HeaderType)BitConverter.ToUInt32(fileHeader, 14);

            switch (HeaderSize)
            {
                case HeaderType.BITMAPCOREHEADER:
                    _bitmapCoreHeader = new BitmapCoreHeader(stream);
                    break;

                case HeaderType.BITMAPINFOHEADER:
                case HeaderType.BITMAPCOREHEADER2:
                case HeaderType.BITMAPV2INFOHEADER:
                case HeaderType.BITMAPV3INFOHEADER:
                case HeaderType.BITMAPV4HEADER:
                case HeaderType.BITMAPV5HEADER:
                    BitmapInfoHeader infoHeader = new BitmapInfoHeader(stream);
                    _bitmapCoreHeader = infoHeader;
                    if(infoHeader.CompressionType == CompressionType.BI_BITFIELDS
                        || infoHeader.CompressionType == CompressionType.BI_ALPHABITFIELDS)
                        BitMask = new BitMask(HeaderSize, infoHeader.CompressionType, stream);

                    break;
            }
        }