Sample pixel value under a transparent window?
Posted: Tue Apr 05, 2022 1:06 pm
Hi all.
I'm struggling with this and am hoping some kind soul might be able to point me in the correct direction.
I'd like to sample pixel values under a transparent window, code below. I think what's happening is I'm instead sampling the value of the transparent window itself, though that may not be the case!
Anyone have any ideas where I'm going wrong and how best I should go about this?
Many thanks in advance.
I'm struggling with this and am hoping some kind soul might be able to point me in the correct direction.
I'd like to sample pixel values under a transparent window, code below. I think what's happening is I'm instead sampling the value of the transparent window itself, though that may not be the case!
Anyone have any ideas where I'm going wrong and how best I should go about this?
Many thanks in advance.
Code: Select all
;// ----------------------------------------------------------------------------------------------
; Create a small transparent window and get the pixel value(s) under it
;// ----------------------------------------------------------------------------------------------
Enumeration
#TransWin
#img
EndEnumeration
;// ----------------------------------------------------------------------------------------------
Procedure TransWin()
;// source: https://www.purebasic.fr/english/viewtopic.php?f=5&t=45362&hilit=+transparent
If OpenWindow(#TransWin, 0, 0, 144, 10, "Grab Window",#PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered)
SetWindowColor(#TransWin,#Blue)
SetWindowLong_(WindowID(#TransWin), #GWL_EXSTYLE, #WS_EX_LAYERED | #WS_EX_TOPMOST)
SetLayeredWindowAttributes_(WindowID(#TransWin),#Blue,0,#LWA_COLORKEY)
EndIf
EndProcedure
;// ----------------------------------------------------------------------------------------------
TransWin() ;// Draw the transparent window
CreateImage(#img, 144, 10, 32, #PB_Image_Transparent)
StartDrawing(WindowOutput(#TransWin))
While (#True) ;// just loop for now
Event = WindowEvent() ;// Non blocking wait for window event
If Event = #PB_Event_CloseWindow ;// window closed ? if yes then exit program
Goto exit
EndIf
Debug Point(1, 6) ;// sample pixel under transparent window at coord 1,6
;// draw a white line in middle of transparent window -
;// - to aid "lining up"
For i = 0 To 143 : Plot(i,5,RGB(255,255,255)) : Next
Wend
StopDrawing()
;// ----------------------------------------------------------------------------------------------
exit:
StopDrawing()
End
;// ----------------------------------------------------------------------------------------------