Exemplo n.º 1
0
        static void AdjustImage(string Filename, int Hue, int Saturation, int Lightness)
        {
            Bitmap bmp = new Bitmap(Filename);

            if (bmp != null)
            {
                Bitmap b = null;
                bool is9Patch = (Filename.ToLower().IndexOf(".9.png", Filename.Length - 6) != -1);

                String tempstr = "HSL:{" + String.Format("{0},{1},{2}", Hue.ToString(),
                    Saturation.ToString(), Lightness.ToString()) + "}";
                Console.WriteLine(tempstr.PadRight(21, ' ') + Path.GetFileName(Filename));

                AdjustPixel pixel = new AdjustPixel();
                pixel.HueSaturationLightness(Hue, Saturation, Lightness);
                b = new Bitmap(bmp.Width, bmp.Height);
                if (b != null)
                {
                    Color color;

                    for (int y = 0; y < b.Height; y++)
                    {
                        for (int x = 0; x < b.Width; x++)
                        {
                            color = bmp.GetPixel(x, y);
                            if (is9Patch &&
                                ((x == 0) || (x == b.Width - 1) ||
                                 (y == 0) || (y == b.Height - 1)))
                            {
                                b.SetPixel(x, y, color);
                            }
                            else
                                b.SetPixel(x, y, pixel.ApplyHSL(color));
                        }
                    }
                }
                bmp.Dispose();
                if (b != null)
                    b.Save(Filename);
            }
        }
Exemplo n.º 2
0
        static void GrayscaleImage(string Filename)
        {
            Bitmap bmp = new Bitmap(Filename);

            if (bmp != null)
            {
                Bitmap b = null;
                bool is9Patch = (Filename.ToLower().IndexOf(".9.png", Filename.Length - 6) != -1);

                Console.WriteLine("Grayscale: " + Path.GetFileName(Filename));
                AdjustPixel pixel = new AdjustPixel();
                b = new Bitmap(bmp.Width, bmp.Height);
                if (b != null)
                {
                    Color color;

                    for (int y = 0; y < b.Height; y++)
                    {
                        for (int x = 0; x < b.Width; x++)
                        {
                            color = bmp.GetPixel(x, y);
                            if (is9Patch &&
                                ((x == 0) || (x == b.Width - 1) ||
                                 (y == 0) || (y == b.Height - 1)))
                            {
                                b.SetPixel(x, y, color);
                            }
                            else
                                b.SetPixel(x, y, pixel.Grayscale(color));
                        }
                    }
                }
                bmp.Dispose();
                if (b != null)
                    b.Save(Filename);
            }
        }