Exemple #1
0
        /// <summary>
        /// Writes the indexed PNG or GIF file
        /// </summary>
        /// <param name="i"></param>
        /// <param name="s"></param>
        public void Write(Image i, System.IO.Stream s)
        {
            bool useMax = (Colors < 0);
            byte colors = (byte)Math.Min(Math.Max(this.Colors, 1), 255);

            if (ImageFormat.Png.Equals(OutputFormat))
            {
                if (useMax)
                {
                    DefaultEncoder.SavePng(i, s);
                }
                else
                {
                    SaveIndexed(ImageFormat.Png, i, s, colors, Dither || FourPassDither, FourPassDither, DitherPercent);
                }
            }
            else if (ImageFormat.Gif.Equals(OutputFormat))
            {
                if (useMax)
                {
                    SaveIndexed(ImageFormat.Gif, i, s, 255, Dither || FourPassDither, FourPassDither, DitherPercent);
                }
                else
                {
                    SaveIndexed(ImageFormat.Gif, i, s, colors, Dither || FourPassDither, FourPassDither, DitherPercent);
                }
            }
        }