matthew1988 Posted July 11, 2012 Posted July 11, 2012 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: 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! :) Quote
Leaders snarfblam Posted July 11, 2012 Leaders Posted July 11, 2012 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. Quote [sIGPIC]e[/sIGPIC]
matthew1988 Posted July 12, 2012 Author Posted July 12, 2012 Ok, so this is what I have so far: 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? :) Quote
Leaders snarfblam Posted July 12, 2012 Leaders Posted July 12, 2012 But... I linked to a working code. Why don't you post what you've tried so far, and explain the trouble you're having. If it helps, here is another very similar but more thorough article. Quote [sIGPIC]e[/sIGPIC]
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.