예제 #1
0
 private void WriteImageGamma()
 {
     using (var chunk = new PngChunkStream(output, PngChunkIdentifier.ImageGamma))
     {
         chunk.WriteBigEndian(45455);
     }
 }
예제 #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);
     }
 }
예제 #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);
                }
            }
        }
예제 #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
            }
        }
예제 #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);
             }
         }
     }
 }
예제 #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);
                }
            }
        }