- Home /
select all pixels with same color ?
Hi ... Are there any way to make something like the this image ( select all the pixels that around the selected one and the with same color )
Thank you
Note :
Magic wand tool ( found it in Photoshop )
Answer by OrbitGames · Aug 01, 2015 at 02:46 PM
Make a 2 dimensional bool array, with the same width and height as your image. Then get the color at the pressed pixel. Then go through all pixels of the image, and compare the color to the desired one. If it is the same, or just slightly different, set the bool to true, else false. after that you can check in your for example brush code, if the pixel is "selected"(true in the array) and only set the color if it is so.
Note: however, this checks for all the pixels, not just the connected ones. If you want that, I would use some pathfinding methods, to check with open and closed list, if the selected pixels are connected.(Hope this makes sense)
thank you for answering me....
I like your idea , but I want to check just for the closed area , as in image up , just the brown color below the eye selected but the brown up the eye didn't
so how can i check if closed or not , and i don't wanna check all the image ( to make it faster ) ,just start checking from the selected pixel until didn't find same color around it so will stop checking
I was thinking about something like in a* pathfinding (only the open and closed list are of importance).
First, you get the coordinates of your initial click, and put it in the open list.
now while there are items on the open list, get the pixels around it, and put them on the openlist, if they share the color. After all of the pixels around are tested, you put the item on the closed list. So something like this:
List<Vector2> openList;
List<Vector2> closedLit;
while (openList.Count > 0)
{
if (isTheSameColor(openList(0)+Vector2.up) && !onOpenOrClosedList(openList(0)+Vector2.up))
{
openList.Add(openList(0)+Vector2.up);
}
//repeat for other sides
closedList.Add(openList(0));
openList.Remove(0);
}
In the end you are left with the closed list. It contains the coordinates of all the pixels you have selected.
This Code is completly unable to compile, and might have some logical gaps in it, but i hope it makes my point a bit clearer. For Example when trying to add a pixel at the edge of the image, this code might not work.
hey did u manage to do it cuz ill want to do the samething with no luck
Answer by maccabbe · Aug 01, 2015 at 02:49 PM
Magic wand tool is made basically the same way as flood fill.
http://www.codeproject.com/KB/GDI-plus/floodfillincsharp.aspx
http://www.codeproject.com/KB/GDI-plus/queuelinearfloodfill.aspx