예제 #1
0
        void Mouse_MouseMove(InputEventArgs e)
        {
            Color clr;
            Point pt = new Point(e.MousePosition.X - imageLocation.X,
                                 e.MousePosition.Y - imageLocation.Y);

            if (buffer.IsPointValid(pt) == false)
            {
                frm.lblPixelColor.Text = "No Pixel";
                return;
            }

            if (Mouse.Buttons[Mouse.MouseButtons.Primary])
            {
                // do a circle of radius 3
                for (int y = -3; y <= 3; y++)
                {
                    for (int x = -3; x <= 3; x++)
                    {
                        // if we're out of the circle radius, go to the next iteration.
                        if (x * x + y * y > 9)
                        {
                            continue;
                        }

                        Point newpt = new Point(pt.X + x, pt.Y + y);

                        if (newpt.X < 0 || newpt.X >= buffer.Width)
                        {
                            continue;
                        }
                        if (newpt.Y < 0 || newpt.Y >= buffer.Height)
                        {
                            continue;
                        }

                        buffer.SetPixel(newpt.X, newpt.Y, Color.FromArgb(frm.btnColor.BackColor.ToArgb()));
                    }
                }
                image.WritePixels(buffer);
            }

            clr = buffer.GetPixel(e.MousePosition.X - imageLocation.X,
                                  e.MousePosition.Y - imageLocation.Y);

            frm.lblPixelColor.Text =
                string.Format("R: {0}  G: {1}\r\nB: {2}  A: {3}",
                              FormatComponent(clr.R), FormatComponent(clr.G),
                              FormatComponent(clr.B), FormatComponent(clr.A));
        }