با درود
کد سطل رنگ که برای انجام کار تابع fill ر افراخوانی میکند موقع اجرا هنگ میکند , در واقع پس از انتخاب یک PICTURE BOX که حاوی آیکون سطل رنگ میباشد , آرگومان های موقعیت به تابع ارسال شده و تابع fill میبایست منطقه انتخاب شده ای که در ان کلیک میشود را با رنگ پر کند اما هیچ اتفاقی نمی افتد. لطفا ضمن بررسی کد ها در صورتیکه راه حلی دارید راهنمایی بفرمایید.
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (act == "color")
{
fill(bmp ,e.X, e.Y, bmp.GetPixel(e.X, e.Y));
pictureBox1.Image = bmp;
}
}
=========
private void fill(Bitmap picture, int x, int y, Color bcolor)
{
if (x > 0 && x < picture.Width && y > 0 && y < picture.Height)
{
Point p = new Point(x, y);
Stack<Point> s = new Stack<Point>();
s.Push(p);
while (s.Count > 0)
{
p = s.Pop();
Color currentcolor = picture.GetPixel(p.X, p.Y);
if (currentcolor == bcolor)
{
this.Refresh();
picture.SetPixel(p.X, p.Y, currentcolor);
s.Push(new Point(p.X - 1, p.Y));
s.Push(new Point(p.X + 1, p.Y));
s.Push(new Point(p.X, p.Y - 1));
s.Push(new Point(p.X, p.Y + 1));
}
}
}
}