Color Eyedropper
Posted: Mon May 04, 2015 4:09 am
Here is a color "eyedropper" for displaying the RGB values of any pixel on the screen. Feel free to add enhancements. Many thanks to Franco and anyone else who contributed.
Code: Select all
;Original loupe code by Franco
#WI = 1:#HE=1
Procedure CaptureScreen(Left.l, Top.l)
DC = GetDC_(0)
MemDC = CreateCompatibleDC_(DC)
BmpID = CreateImage(0, #WI, #HE)
SelectObject_( MemDC, BmpID)
StretchBlt_( MemDC, 0, 0,#WI,#HE, DC,Left, Top, #WI, #HE, #SRCCOPY)
DeleteDC_( MemDC)
ReleaseDC_(0,DC)
ProcedureReturn BmpID
EndProcedure
If OpenWindow(0,0,0,200,200,"R G B",#PB_Window_SystemMenu)
StickyWindow(0,#True)
Else : End : EndIf
CursorPosition.POINT
StartDrawing(WindowOutput(0))
Repeat
EventID = WaitWindowEvent(10)
GetCursorPos_(CursorPosition)
hImage = CaptureScreen(CursorPosition\x,CursorPosition\y)
DrawImage(hImage, 0, 0,#WI,#HE)
re = Red(Point(0,0)):DrawText(25,15,"Red: "+Str(re)+" "+LCase(Hex(re))+" ",#White,$0000aa)
gr = Green(Point(0,0)):DrawText(25,35,"Green: "+Str(gr)+" "+LCase(Hex(gr))+" ",#White,$00aa00)
bl = Blue(Point(0,0)):DrawText(25,55,"Blue: "+Str(bl)+" "+LCase(Hex(bl))+" ",#White,$ff0000)
Box(45,90,100,100,RGB(re,gr,bl))
Until EventID=#PB_Event_CloseWindow
End