예제 #1
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(Image image, Stream stream)
        {
            // Write the png header.
            stream.Write(s_pngHeader, 0, 8);

            PngHeader header = new PngHeader();
            header.Width = image.Width;
            header.Height = image.Height;
            header.ColorType = 6;
            header.BitDepth = 8;
            header.FilterMethod = 0;
            header.CompressionMethod = 0;
            header.InterlaceMethod = 0;

            WriteHeaderChunk(stream, header);
            WriteDataChunks(stream, image);
            WriteEndChunk(stream);

            stream.Flush();
        }
예제 #2
0
            private void ReadHeaderChunk(byte[] data)
            {
                _header = new PngHeader();

                Array.Reverse(data, 0, 4);
                Array.Reverse(data, 4, 4);

                _header.Width = BitConverter.ToInt32(data, 0);
                _header.Height = BitConverter.ToInt32(data, 4);

                _header.BitDepth = data[8];
                _header.ColorType = data[9];
                _header.FilterMethod = data[11];
                _header.InterlaceMethod = data[12];
                _header.CompressionMethod = data[10];
            }
예제 #3
0
        private void WriteHeaderChunk(Stream stream, PngHeader header)
        {
            byte[] chunkData = new byte[13];

            WriteInteger(chunkData, 0, header.Width);
            WriteInteger(chunkData, 4, header.Height);

            chunkData[8] = header.BitDepth;
            chunkData[9] = header.ColorType;
            chunkData[10] = header.CompressionMethod;
            chunkData[11] = header.FilterMethod;
            chunkData[12] = header.InterlaceMethod;

            WriteChunk(stream, PngChunkTypes.Header, chunkData);
        }