using System;
using System.Drawing;
using System.Collections;
namespace drawing
{
/// <summary>
/// tianchong 的摘要说明。
/// </summary>
public class tianchong
{
public tianchong()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public void fill(int x, int y, Color newColor,Image CurImage)
{Point OldPoint=new Point();
Image image=CurImage;
// Color curcolor=new Color();
Point NewPoint=new Point();
Stack MyStack=new Stack();
Color FillColor=newColor;
Bitmap bitmap=new Bitmap(CurImage);
Color OldColor=bitmap.GetPixel(x,y);
MyStack.Push(new Point(x,y));
while(MyStack.Count!=0)
{
NewPoint=(Point)MyStack.Pop();
bitmap.SetPixel(NewPoint.X,NewPoint.Y,FillColor);
image=bitmap;
// curcolor=bitmap.GetPixel(NewPoint.X,NewPoint.Y);
if(bitmap.GetPixel(NewPoint.X+1,NewPoint.Y)!=FillColor && bitmap.GetPixel(NewPoint.X+1,NewPoint.Y)==OldColor)
{
MyStack.Push(new Point(NewPoint.X+1,NewPoint.Y));
}
if(bitmap.GetPixel(NewPoint.X,NewPoint.Y+1)!=FillColor && bitmap.GetPixel(NewPoint.X,NewPoint.Y+1)==OldColor)
{
MyStack.Push(new Point(NewPoint.X,NewPoint.Y+1));
}
if(bitmap.GetPixel(NewPoint.X-1,NewPoint.Y)!=FillColor && bitmap.GetPixel(NewPoint.X-1,NewPoint.Y)==OldColor)
{
MyStack.Push(new Point(NewPoint.X-1,NewPoint.Y));
}
if(bitmap.GetPixel(NewPoint.X,NewPoint.Y-1)!=FillColor && bitmap.GetPixel(NewPoint.X,NewPoint.Y-1)==OldColor)
{
MyStack.Push(new Point(NewPoint.X,NewPoint.Y-1));
}
}
}
}
}
不知道怎么回事画不出来,高手帮一下,用的是种子填充,看看是不是这个类的毛病.