コード例 #1
0
        //default 8-pallete
        public static Bitmap BurkesColorDithering(Bitmap sourceImage, int paletteSize)
        {
            ColorImageQuantizer ciq = new ColorImageQuantizer(new MedianCutQuantizer());

            Color[] colorTable          = ciq.CalculatePalette(sourceImage, paletteSize);
            BurkesColorDithering filter = new BurkesColorDithering();

            filter.ColorTable = colorTable;
            return(filter.Apply(sourceImage));
        }
コード例 #2
0
        private Bitmap reducedColor(Bitmap image, int numColors)
        {
            // create color image quantization routine
            ColorImageQuantizer ciq = new ColorImageQuantizer(new MedianCutQuantizer());

            // create 16 colors table
            Color[] colorTable = ciq.CalculatePalette(image, numColors);
            // create dithering routine
            FloydSteinbergColorDithering dithering = new FloydSteinbergColorDithering();

            dithering.ColorTable = colorTable;
            // apply the dithering routine
            Bitmap newImage = dithering.Apply(image);

            return(newImage);
        }
コード例 #3
0
        public static Bitmap OrderedColorDithering(Bitmap bmp, int value)
        {
            // create color image quantization routine
            ColorImageQuantizer ciq = new ColorImageQuantizer(new MedianCutQuantizer());

            // create 256 colors table
            Color[] colorTable = ciq.CalculatePalette(bmp, value);
            // create dithering routine
            OrderedColorDithering dithering = new OrderedColorDithering();

            dithering.ColorTable = colorTable;
            // apply the dithering routine
            Bitmap newImage = dithering.Apply(bmp);

            return(newImage);
        }
コード例 #4
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("There was no file specified.");
                filename = "i_eat_ass.png";
            }
            else
            {
                filename = args[0];
            }

            Image  imageFile = Image.FromFile(filename);
            Bitmap bmp       = new Bitmap(imageFile);

            ColorImageQuantizer ciq = new ColorImageQuantizer(new MedianCutQuantizer());

            Color[] colorTable = ciq.CalculatePalette(bmp, 16);
            Dictionary <String, int> colorMap = new Dictionary <String, int>();

            for (int i = 0; i < colorTable.Length; i++)
            {
                try
                {
                    colorMap.Add(colorTable[i].ToString(), i);
                }
                catch (System.ArgumentException e) {
                }
            }


            Bitmap RImage = ciq.ReduceColors(bmp, colorTable);



            int[] flatImage = new int[RImage.Width * RImage.Height];
            for (int x = 0; x < RImage.Width; x++)
            {
                for (int y = 0; y < RImage.Height; y++)
                {
                    flatImage[x + RImage.Width * y] = colorMap[RImage.GetPixel(x, y).ToString()];
                }
            }
            output.AddRange(Encoding.UTF8.GetBytes("YAIF"));
            Add16BitInt(2);
            Add16BitInt(bmp.Width);
            Add16BitInt(bmp.Height);
            Add8BitInt(colorTable.Length * 3);
            Add32BitInt(flatImage.Length / 2);
            output.AddRange(Encoding.UTF8.GetBytes("F**K"));

            for (int i = 0; i < colorTable.Length; i++)
            {
                Add8BitInt(colorTable[i].R);
                Add8BitInt(colorTable[i].G);
                Add8BitInt(colorTable[i].B);
            }

            for (int i = 0; i < flatImage.Length; i += 2)
            {
                AddNibbles(flatImage[i], flatImage[i + 1]);
            }

            byte[] outputArray = output.ToArray();
            File.WriteAllBytes(args[0].Split('.')[0] + ".yaif", outputArray);
        }