Exemplo n.º 1
0
        /// <summary>
        /// Encodes and writes pixel data to the supplied stream
        /// </summary>
        /// <param name="indexedPixels">
        /// Collection of indices of the pixel colours within the active colour
        /// table.
        /// </param>
        /// <param name="outputStream">
        /// The stream to write to.
        /// </param>
        private static void WritePixels(IndexedPixels indexedPixels,
                                        Stream outputStream)
        {
            LzwEncoder encoder = new LzwEncoder(indexedPixels);

            encoder.Encode(outputStream);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Converts the supplied image to a collection of pixel indices using
        /// the supplied colour table.
        /// Only used when the QuantizerType is set to UseSuppliedPalette
        /// </summary>
        /// <param name="act">The active colour table</param>
        /// <param name="image">The image</param>
        /// <returns></returns>
        private IndexedPixels MakeIndexedPixels(ColourTable act, Image image)
        {
            int    pixelCount  = image.Height * image.Width;
            string counterText = "Getting indices in colour table";

            AddCounter(counterText, pixelCount);
            Bitmap        bitmap = (Bitmap)image;
            IndexedPixels ip     = new IndexedPixels();

            for (int y = 0; y < image.Height; y++)
            {
                for (int x = 0; x < image.Width; x++)
                {
                    Color c     = bitmap.GetPixel(x, y);
                    int   index = FindClosest(c, act);
                    ip.Add((byte)index);
                    MyProgressCounters[counterText].Value = ip.Count;
                }
            }
            RemoveCounter(counterText);
            return(ip);
        }