[英]Fill in Function in PictureBox in Visual Studio C#?
Is there any function to automatically fill in one of these states in brazil with a certain color, but without their neighbour state?是否有任何功能可以在巴西用某种颜色自动填充这些状态之一,但没有它们的邻居状态? So as an example, i have the coordinate 150x and 200y for the picturebox in c# Visual Studio.
例如,我在 c# Visual Studio 中的图片框坐标为 150x 和 200y。 And i want that from this point everything grey that surrounds this point should turn into blue, but it should stop at the white border.
我希望从这一点开始,围绕这一点的所有灰色都应该变成蓝色,但它应该停在白色边框处。 Is there any function to do that, without declaring specific polygons for each state?
是否有任何功能可以做到这一点,而无需为每个州声明特定的多边形? Thanks for all Answers!
感谢所有的答案!
Here I have an idea that you can use recursion
to traverse the pixels and modify their color.在这里,我有一个想法,您可以使用
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);
}
}
The test result,测试结果,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.