Пример #1
0
 private static void Write(BinaryWriter writer, BmpFileHeader fileHeader)
 {
     writer.Write(fileHeader.Type);
     writer.Write(fileHeader.FileSize);
     writer.Write(fileHeader.Reserved);
     writer.Write(fileHeader.Offset);
 }
Пример #2
0
        private void ReadFileHeader()
        {
            byte[] data = new byte[BmpFileHeader.Size];

            _stream.Read(data, 0, BmpFileHeader.Size);

            _fileHeader          = new BmpFileHeader();
            _fileHeader.Type     = BitConverter.ToInt16(data, 0);
            _fileHeader.FileSize = BitConverter.ToInt32(data, 2);
            _fileHeader.Reserved = BitConverter.ToInt32(data, 6);
            _fileHeader.Offset   = BitConverter.ToInt32(data, 10);
        }
Пример #3
0
        /// <summary>
        /// Encodes the data of the specified image and writes the result to
        /// the specified stream.
        /// </summary>
        /// <param name="image">The image, where the data should be get from.
        /// Cannot be null (Nothing in Visual Basic).</param>
        /// <param name="stream">The stream, where the image data should be written to.
        /// Cannot be null (Nothing in Visual Basic).</param>
        /// <exception cref="ArgumentNullException">
        ///     <para><paramref name="image"/> is null (Nothing in Visual Basic).</para>
        ///     <para>- or -</para>
        ///     <para><paramref name="stream"/> is null (Nothing in Visual Basic).</para>
        /// </exception>
        public void Encode(ExtendedImage image, Stream stream)
        {
            Guard.NotNull(image, "image");
            Guard.NotNull(stream, "stream");

            int rowWidth = image.PixelWidth;

            int amount = (image.PixelWidth * 3) % 4;

            if (amount != 0)
            {
                rowWidth += 4 - amount;
            }

            BinaryWriter writer = new BinaryWriter(stream);

            BmpFileHeader fileHeader = new BmpFileHeader();

            fileHeader.Type     = 19778;
            fileHeader.Offset   = 54;
            fileHeader.FileSize = 54 + image.PixelHeight * rowWidth * 3;
            Write(writer, fileHeader);

            BmpInfoHeader infoHeader = new BmpInfoHeader();

            infoHeader.HeaderSize   = 40;
            infoHeader.Height       = image.PixelHeight;
            infoHeader.Width        = image.PixelWidth;
            infoHeader.BitsPerPixel = 24;
            infoHeader.Planes       = 1;
            infoHeader.Compression  = BmpCompression.RGB;
            infoHeader.ImageSize    = image.PixelHeight * rowWidth * 3;
            infoHeader.ClrUsed      = 0;
            infoHeader.ClrImportant = 0;
            Write(writer, infoHeader);

            WriteImage(writer, image);

            writer.Flush();
        }
Пример #4
0
        /// <summary>
        /// Encodes the data of the specified image and writes the result to
        /// the specified stream.
        /// </summary>
        /// <param name="image">The image, where the data should be get from.
        /// Cannot be null (Nothing in Visual Basic).</param>
        /// <param name="stream">The stream, where the image data should be written to. 
        /// Cannot be null (Nothing in Visual Basic).</param>
        /// <exception cref="ArgumentNullException">
        /// 	<para><paramref name="image"/> is null (Nothing in Visual Basic).</para>
        /// 	<para>- or -</para>
        /// 	<para><paramref name="stream"/> is null (Nothing in Visual Basic).</para>
        /// </exception>
        public void Encode(ExtendedImage image, Stream stream)
        {
            Guard.NotNull(image, "image");
            Guard.NotNull(stream, "stream");

            int rowWidth = image.PixelWidth;

            int amount = (image.PixelWidth * 3) % 4; 
            if (amount != 0)
            {
                rowWidth += 4 - amount;
            }

            BinaryWriter writer = new BinaryWriter(stream);

            BmpFileHeader fileHeader = new BmpFileHeader();
            fileHeader.Type = 19778;
            fileHeader.Offset = 54;
            fileHeader.FileSize = 54 + image.PixelHeight * rowWidth * 3;
            Write(writer, fileHeader);

            BmpInfoHeader infoHeader = new BmpInfoHeader();
            infoHeader.HeaderSize = 40;
            infoHeader.Height = image.PixelHeight;
            infoHeader.Width = image.PixelWidth;
            infoHeader.BitsPerPixel = 24;
            infoHeader.Planes = 1;
            infoHeader.Compression = BmpCompression.RGB;
            infoHeader.ImageSize = image.PixelHeight * rowWidth * 3;
            infoHeader.ClrUsed = 0;
            infoHeader.ClrImportant = 0;
            Write(writer, infoHeader);

            WriteImage(writer, image);

            writer.Flush();
        }
Пример #5
0
 private static void Write(BinaryWriter writer, BmpFileHeader fileHeader)
 {
     writer.Write(fileHeader.Type);
     writer.Write(fileHeader.FileSize);
     writer.Write(fileHeader.Reserved);
     writer.Write(fileHeader.Offset);
 }
Пример #6
0
        private void ReadFileHeader()
        {
            byte[] data = new byte[BmpFileHeader.Size];

            _stream.Read(data, 0, BmpFileHeader.Size);

            _fileHeader = new BmpFileHeader();
            _fileHeader.Type = BitConverter.ToInt16(data, 0);
            _fileHeader.FileSize = BitConverter.ToInt32(data, 2);
            _fileHeader.Reserved = BitConverter.ToInt32(data, 6);
            _fileHeader.Offset = BitConverter.ToInt32(data, 10);
        }