Answer the question
In order to leave comments, you need to log in
C# - Find a pixel/group of pixels in a Bitmap?
Hello, there is a certain bitmap in which you need to find a pixel with a certain color. Searching by enumeration:
for (int w = 0; w < bmap.Width; w++)
{
for (int h = 0; h < bmap.Height; h++)
{
clr_ = bmap.GetPixel(w, h).R + bmap. GetPixel(w, h).G + bmap.GetPixel(w, h).B;
.....
}
}
On a 1920x1080 image, it takes about 5 seconds. How can you speed up? It is also interesting if the search is not for 1 pixel, but for a group (sprite) ...
Answer the question
In order to leave comments, you need to log in
yes, lockbits. The finished solution was here: www.cyberforum.ru/windows-forms/thread1045100.html
Break the bitmap into sectors and process each sector in a separate thread (ThreadPool, Parallel or Task with the launch of child tasks and the ability to cancel when found) + as mentioned above, useBitmap.LockBits.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question