Find Pixel Loop

matthew1988

Newcomer
Joined
Jul 10, 2012
Messages
2
Hello!

I would like to know what is the fastest way to find a pixel on my desktop. I've tried GetPixel API, but it's extremely slow. I've also tried Bitmap.GetPixel and it doesn't seem to be a difference between the two.

I'm trying to search for exactly one pixel on my desktop. I have the coordinate as well as the color. It has to be in a loop if you don't mind.

Here's how I used GetPixel:

Code:
Do
'Nothing
Loop Until GetPixel(hDC,X,Y) = COLOR

If there's anything you need to know, please ask. Thank you for this wonderful forum! :)
 
GetPixel (either version) is notoriously slow. What you really want to do is access the raw image data. You can use a Graphics object to copy the desktop to a bitmap, and there are a bunch of tutorials around on how to access raw bitmap data in .NET.
 
Ok, so this is what I have so far:

Code:
Dim Size As New Size(1, 1)
        Using BMP As New Bitmap(1, 1)
            Using G = Graphics.FromImage(BMP)
                Do
                    Dim FoundColor As Color
                    G.CopyFromScreen(Point, Point.Empty, Size)
                    FoundColor = BMP.GetPixel(0, 0)
                    Loop Until FoundColor.ToArgb = Color.ToArgb

Still very slow... -_-. I think maybe I should use lockbits and marshall? But, I've tried and can't even come up with a working sample...

Do you mind posting a super fast lockbits example? :)
 
Back
Top