Page 1 of 1

Find pixel color on screen?

Posted: Thu Oct 13, 2005 12:01 am
by roachofdeath
Hi, I was wondering how I would go about finding the pixel color of a pixel on the screen, and not just the window?

I know about GetPixel_, but I am unsure on the parameters for it.

Re: Find pixel color on screen?

Posted: Thu Oct 13, 2005 11:52 am
by PB
This is something I cut down from other examples in these forums... it shows
the color of the pixel under the mouse pointer when you run it. Maybe you
should stick it in a loop or something? :)

Code: Select all

dc=CreateDC_("DISPLAY",0,0,0) : GetCursorPos_(mouse.POINT)
p=GetPixel_(dc,mouse\x,mouse\y) : DeleteDC_(dc)
Debug "R="+Str(Red(p))+", G="+Str(Green(p))+", B="+Str(Blue(p))

Posted: Sat Oct 15, 2005 1:43 am
by akj
There is also PB's Point() function.

Posted: Sat Oct 15, 2005 3:16 am
by roachofdeath
on the screen, and not just the window

Posted: Sat Oct 15, 2005 3:25 am
by Dare2
Hi roachofdeath,

Would a simplistic way work for you? Eg, do a screencapture (various code snippets in codearchive on www.purearea.net - windows-system and screenshots directory) and then get the point of the captured image?

Posted: Sat Oct 15, 2005 3:29 am
by roachofdeath
Seems logical, but a lot easier (and probably easier for the computer too) to just use the API call ;)

Posted: Sat Oct 15, 2005 3:38 am
by PB
> just use the API call

Yep -- no need to create a screenshot or use the 2D graphics library. :)

Posted: Fri Oct 21, 2005 12:04 pm
by PHP
Has anyone now a working solution for the whole screen and not only the window?

Posted: Fri Oct 21, 2005 7:18 pm
by Henrik
Hi PHP
But PB's example works
Here in a Repeat - ForEver Loop
With a 500 millisc. delay
Remember to kill the program from the editor as it run's forever

Code: Select all

Repeat
dc=CreateDC_("DISPLAY",0,0,0) : GetCursorPos_(mouse.POINT)
p=GetPixel_(dc,mouse\x,mouse\y) : DeleteDC_(dc)
Debug "R="+Str(Red(p))+", G="+Str(Green(p))+", B="+Str(Blue(p)) 
Delay (500)
ForEver
Best regrads
Henrik

Posted: Fri Oct 21, 2005 9:24 pm
by Droopy

Code: Select all

; Return the RGB color of the pixel at the specified coordinates
; or #CLR_INVALID (-1) if coordinates is outside the screen

ProcedureDLL GetPixelColor(x,y)
  sysviewDC = GetDC_( hwndSysview ) 
  ProcedureReturn GetPixel_( sysviewDC,x, y ) 
EndProcedure
In the Droopy Lib ...

Posted: Sat Oct 22, 2005 1:26 am
by PB
> Has anyone now a working solution for the whole screen and not only the window?

Obviously you didn't try my tip. :twisted: