在这里,我有一个想法,您可以recursion
用来遍历像素并修改其颜色。
Bitmap bmp;
private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
{
int x = e.X;
int y = e.Y;
bmp = (Bitmap)pictureBox1.Image;
ModifyMap(x, y);
pictureBox1.Image = bmp;
}
// Recursion
private void ModifyMap(int x, int y)
{
// the color info of gray part "Color [A=255, R=153, G=153, B=153]"
if (bmp.GetPixel(x, y).ToString() == "Color [A=255, R=153, G=153, B=153]")
{
bmp.SetPixel(x, y, Color.Blue);
ModifyMap(x + 1, y);
ModifyMap(x - 1, y);
ModifyMap(x, y + 1);
ModifyMap(x, y - 1);
}
}
测试结果
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句