Ejemplo n.º 1
0
 private void WriteImageGamma()
 {
     using (var chunk = new PngChunkStream(output, PngChunkIdentifier.ImageGamma))
     {
         chunk.WriteBigEndian(45455);
     }
 }
Ejemplo n.º 2
0
 private void WriteTextualData(string key, string value)
 {
     using (var chunk = new PngChunkStream(output, PngChunkIdentifier.TextualData))
     {
         chunk.Write(key);
         chunk.WriteByte(0);
         chunk.Write(value);
     }
 }
Ejemplo n.º 3
0
        private void WriteTransparency()
        {
            if (palette.Count == 0 || !palette.HasAlphaChannel)
            {
                return;
            }

            using (var chunk = new PngChunkStream(output, PngChunkIdentifier.Transparency))
            {
                for (var i = 0; i < palette.Count; i++)
                {
                    chunk.WriteByte((byte)palette[i].A);
                }
            }
        }
Ejemplo n.º 4
0
        private void WriteImageHeader()
        {
            using (var chunk = new PngChunkStream(output, PngChunkIdentifier.ImageHeader))
            {
                var colorType = palette.Count > 0 ?
                                PngColorType.IndexedColour : PngColorType.TruecolourWithAlpha;

                chunk.WriteBigEndian(Width);
                chunk.WriteBigEndian(Height);
                chunk.WriteByte(8); // Bit depth
                chunk.WriteByte(colorType);
                chunk.WriteByte(0); // Compression
                chunk.WriteByte(0); // Filter
                chunk.WriteByte(0); // Interlace
            }
        }
Ejemplo n.º 5
0
 private void WriteImageData()
 {
     using (var chunk = new PngChunkStream(output, PngChunkIdentifier.ImageData))
     {
         using (var deflate = new ZlibStream(chunk))
         {
             if (palette.Count > 0)
             {
                 WriteIndexed(deflate);
             }
             else
             {
                 WriteTrueColorWithAlpha(deflate);
             }
         }
     }
 }
Ejemplo n.º 6
0
        private void WritePalette()
        {
            if (palette.Count == 0)
            {
                return;
            }

            using (var chunk = new PngChunkStream(output, PngChunkIdentifier.Palette))
            {
                for (var i = 0; i < palette.Count; i++)
                {
                    chunk.WriteByte((byte)palette[i].R);
                    chunk.WriteByte((byte)palette[i].G);
                    chunk.WriteByte((byte)palette[i].B);
                }
            }
        }