Пример #1
0
        private static void TransferPalette(Pix pix, Bitmap img)
        {
            var palette   = img.Palette;
            var maxColors = palette.Entries.Length;
            var lastColor = maxColors - 1;
            var colormap  = pix.pixGetColormap();// pix.Colormap;

            if (colormap != null && colormap.pixcmapGetCount() <= maxColors)
            {
                var colormapCount = colormap.pixcmapGetCount();
                for (int i = 0; i < colormapCount; i++)
                {
                    palette.Entries[i] = colormap[i];
                }
            }
            else
            {
                for (int i = 0; i < maxColors; i++)
                {
                    var value = (byte)(i * 255 / lastColor);
                    palette.Entries[i] = Color.FromArgb(value, value, value);
                }
            }

            // This is required to force the palette to update!
            img.Palette = palette;
        }