示例#1
0
        private static BITMAPFILEHEADER LoadFileHeader(string FileLocation)
        {
            BITMAPFILEHEADER Structure;

            using (Stream BitmapFileStream = new FileStream(FileLocation, FileMode.Open))
                using (BinaryReader Reader = new BinaryReader(BitmapFileStream))
                {
                    Reader.BaseStream.Position = 0L;
                    Structure             = new BITMAPFILEHEADER();
                    Structure.bfType      = Reader.ReadUInt16();
                    Structure.bfSize      = Reader.ReadUInt32();
                    Structure.bfReserved1 = Reader.ReadUInt16();
                    Structure.bfReserved2 = Reader.ReadUInt16();
                    Structure.bfOffBits   = Reader.ReadUInt32();
                }

            return(Structure);
        }
示例#2
0
        public BitmapFile(string FileLocation)
        {
            try
            {
                //Load Headers...
                fileHeader = LoadFileHeader(FileLocation);
                infoHeader = LoadInfoHeader(FileLocation);

                //Read Raw data
                using (Stream BitmapFileStream = new FileStream(FileLocation, FileMode.Open))
                    using (BinaryReader Reader = new BinaryReader(BitmapFileStream))
                    {
                        BitmapFileStream.Position = 54L;
                        raw = Reader.ReadBytes((int)infoHeader.biSizeImage);
                    }
            }
            catch (IOException)
            {
                throw new IOException("Unable to read Bitmap File. File might be corrupt, or being used in another location");
            }
        }