private void pictureBox1_Click(object sender, EventArgs e)
        {
            double expectedHue = (double)picX / pictureBox.Width;
            double expectedVal = (double)picY / pictureBox.Height;

            pickedColor = ColorRGB.HSL2RGB(expectedHue, 1, expectedVal);

            for (int i = 0; i < img.Width; i++)
            {
                for (int j = 0; j < img.Height; j++)
                {
                    Color c = img.GetPixel(i, j);
                    ColorRGB.RGB2HSL(new ColorRGB(c), out double h, out double s, out double v);
                    h += expectedHue - midHue;
                    if (h < 0)
                    {
                        h += 1;
                    }
                    if (h > 1)
                    {
                        h -= 1;
                    }

                    Color o  = ColorRGB.HSL2RGB(h, s, v);
                    Color oa = Color.FromArgb(c.A, o.R, o.G, o.B);

                    newImg.SetPixel(i, j, oa);
                }
            }

            Graphics graphics = starPicture.CreateGraphics();

            graphics.Clear(Color.Black);
            graphics.DrawImage(newImg, 0, 0, 220, 220);
        }
        private void pictureBox_Paint(object sender, PaintEventArgs e)
        {
            Bitmap bitmap = new Bitmap(pictureBox.Width, pictureBox.Height);

            for (int i = 0; i < pictureBox.Width; i++)
            {
                for (int j = 0; j < pictureBox.Height; j++)
                {
                    ColorRGB color = ColorRGB.HSL2RGB((double)i / pictureBox.Width, 0.4, (double)j / pictureBox.Height);
                    bitmap.SetPixel(i, j, color);
                }
            }
            e.Graphics.DrawImage(bitmap, 0, 0);
        }
Beispiel #3
0
        public static void Saturate(Bitmap image)
        {
            for (int i = 0; i < image.Width; i++)
            {
                for (int j = 0; j < image.Height; j++)
                {
                    double   h; double s; double l;
                    Color    c    = image.GetPixel(i, j);
                    ColorRGB crgb = new ColorRGB(c);
                    ColorRGB.RGB2HSL(crgb, out h, out s, out l);

                    s = Math.Min(s + 0.1, 1);

                    ColorRGB nrgb = ColorRGB.HSL2RGB(h, s, l);
                    Color    n    = Color.FromArgb(c.A, nrgb.R, nrgb.G, nrgb.B);
                    image.SetPixel(i, j, n);
                }
            }
        }
        private void pictureBox_MouseMove(object sender, MouseEventArgs e)
        {
            picX = e.X; picY = e.Y;
            if (e.Button != MouseButtons.Left)
            {
                return;
            }

            Bitmap img = ld.goldStar;

            double expectedHue = (double)e.X / pictureBox.Width;
            double expectedVal = (double)e.Y / pictureBox.Height;

            pickedColor = ColorRGB.HSL2RGB(expectedHue, 1, expectedVal);

            for (int i = 0; i < img.Width; i++)
            {
                for (int j = 0; j < img.Height; j++)
                {
                    Color c = img.GetPixel(i, j);
                    ColorRGB.RGB2HSL(new ColorRGB(c), out double h, out double s, out double v);
                    h += expectedHue - midHue;
                    if (h < 0)
                    {
                        h += 1;
                    }
                    if (h > 1)
                    {
                        h -= 1;
                    }

                    Color o  = ColorRGB.HSL2RGB(h, s, v);
                    Color oa = Color.FromArgb(c.A, o.R, o.G, o.B);

                    newImg.SetPixel(i, j, oa);
                }
            }

            Graphics graphics = starPicture.CreateGraphics();

            graphics.Clear(Color.Black);
            graphics.DrawImage(newImg, 0, 0, 220, 220);
        }
        public static Bitmap Desaturate(Bitmap goldStar)
        {
            Bitmap darkStar = new Bitmap(goldStar);

            for (int i = 0; i < goldStar.Width; i++)
            {
                for (int j = 0; j < goldStar.Height; j++)
                {
                    double   h; double s; double l;
                    Color    c    = goldStar.GetPixel(i, j);
                    ColorRGB crgb = new ColorRGB(c);
                    ColorRGB.RGB2HSL(crgb, out h, out s, out l);

                    ColorRGB nrgb = ColorRGB.HSL2RGB(h, 0, l);

                    Color n = Color.FromArgb(c.A, nrgb.R, nrgb.G, nrgb.B);

                    darkStar.SetPixel(i, j, n);
                }
            }
            return(darkStar);
        }