Page 1 of 1

Get Pixel Color at Any Screen Point [Windows]

Posted: Wed Apr 22, 2020 4:29 pm
by RASHAD
Hi all

Code: Select all

Global p.POINT

Procedure GetColor() 
  GetCursorPos_(@p.POINT ) 
  hDC = GetDC_(0) 
  If hDC <> 0 
    Color = GetPixel_(hDC,p\x,p\y) 
    ReleaseDC_(0, hDC) 
    ProcedureReturn Color 
  EndIf 
EndProcedure

OpenWindow(0,0,0,150,120,"",#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
TextGadget(0,10,10,180,20,"")
TextGadget(1,10,35,180,20,"")
TextGadget(2,10,60,180,20,"")
TextGadget(3,10,85,180,20,"")

AddWindowTimer(0,125,10)
Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Quit = 1
      
    Case #PB_Event_Timer  
      color = GetColor()
      SetGadgetText(0,"X : "+Str(p\x)+"  Y :  "+Str(p\y))
      SetGadgetText(1,Str(color))
      SetGadgetText(2,"$"+Hex(color))
      SetGadgetText(3,"RGB("+Str(Red(color))+","+Str(Green(color))+ ","+Str(Blue(color))+")")      
  EndSelect
Until Quit = 1


Re: Get Pixel Color at Any Screen Point [Windows]

Posted: Thu Apr 23, 2020 8:07 pm
by Kwai chang caine
Simple and efficient :wink:
Thanks for sharing 8)

Re: Get Pixel Color at Any Screen Point [Windows]

Posted: Tue Apr 05, 2022 5:51 pm
by Cruster
Oh! Very useful :D