Find pixel color on screen?

Just starting out? Need help? Post your questions and find answers here.
roachofdeath
User
User
Posts: 78
Joined: Sun Apr 24, 2005 3:22 am

Find pixel color on screen?

Post 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.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Find pixel color on screen?

Post 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))
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
akj
Enthusiast
Enthusiast
Posts: 668
Joined: Mon Jun 09, 2003 10:08 pm
Location: Nottingham

Post by akj »

There is also PB's Point() function.
Anthony Jordan
roachofdeath
User
User
Posts: 78
Joined: Sun Apr 24, 2005 3:22 am

Post by roachofdeath »

on the screen, and not just the window
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post 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?
@}--`--,-- A rose by any other name ..
roachofdeath
User
User
Posts: 78
Joined: Sun Apr 24, 2005 3:22 am

Post by roachofdeath »

Seems logical, but a lot easier (and probably easier for the computer too) to just use the API call ;)
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> just use the API call

Yep -- no need to create a screenshot or use the 2D graphics library. :)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
PHP
User
User
Posts: 65
Joined: Sat Sep 10, 2005 5:38 pm

Post by PHP »

Has anyone now a working solution for the whole screen and not only the window?
Henrik
Enthusiast
Enthusiast
Posts: 404
Joined: Sat Apr 26, 2003 5:08 pm
Location: Denmark

Post 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
User avatar
Droopy
Enthusiast
Enthusiast
Posts: 658
Joined: Thu Sep 16, 2004 9:50 pm
Location: France
Contact:

Post 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 ...
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post 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:
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Post Reply