Dafür kann man GetPixel_() nehmen, das gibt die Farbe zurück.
Code: Alles auswählen
;
; Danilo, 2005/10/21
;
Procedure UpdateZoom(x,y)
hDC1 = StartDrawing(ImageOutput())
If hDC1
hDesk = GetDesktopWindow_()
hDC2 = GetWindowDC_(hDesk)
If hDC2
;SetStretchBltMode_(hDC1,#COLORONCOLOR)
StretchBlt_(hDC1,0,0,180,180,hDC2,x-4,y-4,9,9,#SRCCOPY)
ReleaseDC_(hDesk,hDC2)
EndIf
DrawingMode(4)
Box(80,80,20,20,$FFFFFF)
StopDrawing()
EndIf
EndProcedure
Procedure GetDeskColor(x,y)
hDesk = GetDesktopWindow_()
hDC = GetWindowDC_(hDesk)
If hDC
color = GetPixel_(hDC,x,y)
ReleaseDC_(hDesk,hDC)
EndIf
ProcedureReturn color
EndProcedure
OpenWindow(0,0,0,310,200,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"Color")
CreateGadgetList(WindowID())
ImageGadget(0, 10,10,180,180,CreateImage(0,180,180))
ImageGadget(1,200,10,100,100,CreateImage(1,100,25))
TextGadget(2,200,45,100,20,"R: 00")
TextGadget(3,200,65,100,20,"G: 00")
TextGadget(4,200,85,100,20,"B: 00")
DefType.POINT mouse, old_mouse
Repeat
Event = WindowEvent()
Select Event
Case #PB_Event_CloseWindow
End
Default
GetCursorPos_(mouse)
If (mouse\x <> old_mouse\x) Or (mouse\y <> old_mouse\y)
old_mouse\x = mouse\x
old_mouse\y = mouse\y
UseImage(0)
UpdateZoom(mouse\x,mouse\y)
SetGadgetState(0,ImageID())
UseImage(1)
color = GetDeskColor(mouse\x,mouse\y)
If StartDrawing(ImageOutput())
Box(0,0,100,25,color)
StopDrawing()
EndIf
SetGadgetState(1,ImageID())
SetGadgetText(2,"R: "+RSet(Hex( Red(color) ),2,"0"))
SetGadgetText(3,"G: "+RSet(Hex(Green(color)),2,"0"))
SetGadgetText(4,"B: "+RSet(Hex(Blue(color) ),2,"0"))
Else
If Event=0
Delay(5)
EndIf
EndIf
EndSelect
ForEver