thippu
Active member
I want to get the points from the flood filling algorithm and Is there any flood fill method that returns the filled points?
- I have a rectangle in a circle and the rectangle is divided by a line and if a user clicks on any part of the rectangle I will get clicked mouse point and I want to color the clicked part of the rectangle.image
- I would like to save the filled color points also for further use.
- I implemented code using flood filling algorithm in c# but it is not working as expected I'm getting out of memory exception, I could not able to find what is wrong with the code.
code:
void FillZone(Bitmap image,int initialX, int initialY,Color fillColor,Color boundaryColor,List<Point> savePoint)
{
Stack<Point> points=new Stack<Point>();
points.Push(new Point(initialX,initialY));
while(points.Count>0)
{
Point currentPoin=poins.Pop();
int x=currentPoin.X;
int y=currentPoin.Y;
if((x>0&& x<pictureBoxImage.Width)&&(y>0&&y<pictureBoxImage.Height))
{
Color current=image.GetPixel(x,y);
if((current!=boundaryColor))&&(current!=fillColor))
{
image.SetPixel(x,y,fillColor);
savePoints.Add(new Point(x,y));
points.Push(new Point(x+1,y));
points.Push(new Point(x-1,y));
points.Push(new Point(x,y-1));
points.Push(new Point(x,y+1));
}
}
}
}
private void MenuItem_Select_Click(object sender,EventArgs e)
{
Point p=new Point();
p.X=m_right_button_X1;
p.Y=m_right_button_Y1;
Bitmap pic=(Bitmap)pictureBoxImage.Image.Clone();
List<Point>regionPoints=new List<Point>();
FillZone(pic,p.X,p.Y,Color.Red,Color.Black,regionPoints);
}
Last edited: