简体   繁体   English

在Visual Studio C#中的PictureBox中填写Function?

[英]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.

相关问题 Visual Studio C中的PictureBox越野车运动# - PictureBox buggy movement in Visual Studio C# 如何使用C#将图像加载到Visual Studio中的PictureBox上 - How to Load an Image onto PictureBox in Visual Studio using C# Visual Studio 2015 C#与PictureBox的缓慢单击 - Visual Studio 2015 C# Slow Click with PictureBox 将外部图像分配给Visual Studio 2008(C#)中的Picturebox? - Assign an external image to a Picturebox in Visual Studio 2008 (C#)? 图片框控件无法正常使用C#.NET(Visual Studio) - picturebox Control is not working C# .NET (Visual Studio) 如何在边界中保持移动PictureBox C#Visual Studio 2010 - How to keep moving PictureBox in boundaries C# Visual Studio 2010 如何使用C#在Visual Studio中的图片框中访问图像的名称 - How do you access the name of the image in a picturebox in Visual Studio using C# 如何在Visual Studio中为迷宫设计项目中的C#中单击图片框? - How to make picturebox in C# clickable in visual Studio for maze design project? 如何才能逐渐且平滑地更改PictureBox的大小? (在Winforms中,C#,Visual Studio 2013) - How can I change PictureBox size incrementally and smoothly ? ( in winforms , c# , visual studio 2013 ) 在Visual Studio(c#)中使用变量代替名称来更改图片框背景色 - Changing picturebox backcolor in Visual Studio (c#) using a variable in place of a name
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM