Jump to content

_GDIPlus_BitmapGetPixel gives me flashing window


Recommended Posts

Hello,

I use a function including _GDIPlus_BitmapGetPixel to get the pixel color from a window in the background.
I found this function somewhere on the forum and don't really know anything about GDIPlus.
 

Func GetColor($iX,$iY,$WinHandle)

    _GDIPlus_Startup()

    Local $aPos = WinGetPos($WinHandle)
    $iWidth = $aPos[2]
    $iHeight = $aPos[3]
    Local $hDDC = _WinAPI_GetDC($WinHandle)
    Local $hCDC = _WinAPI_CreateCompatibleDC($hDDC)

    $hBMP = _WinAPI_CreateCompatibleBitmap($hDDC, $iWidth, $iHeight)


    _WinAPI_SelectObject($hCDC, $hBMP)
    DllCall("User32.dll", "int", "PrintWindow", "hwnd", $WinHandle, "hwnd", $hCDC, "int", 0)
    _WinAPI_BitBlt($hCDC, 0, 0, $iWidth, $iHeight, $hDDC, 0, 0, $__SCREENCAPTURECONSTANT_SRCCOPY)


     $BMP = _GDIPlus_BitmapCreateFromHBITMAP($hBMP)
     Local $aPixelColor = _GDIPlus_BitmapGetPixel($BMP, $iX, $iY)

    _WinAPI_ReleaseDC($WinHandle, $hDDC)
    _WinAPI_DeleteDC($hCDC)
    _WinAPI_DeleteObject($hBMP)
    _GDIPlus_ImageDispose($BMP)
    _GDIPlus_Shutdown()

    Return Hex($aPixelColor, 6)
    
EndFunc


The function is called every 200ms and works fine when the window is in the background. 
But when the window can be seen, it is heavily flashing.
Probably this is not caused by _GDIPlus_BitmapGetPixel itself, but by anything else going on in the function.

I was able to find a workaround for SOME cases by using the usual PixelGetColor whenever WinGetState tells me
the window is active (and in front). I switch to using _GDIPlus_BitmapGetPixel only when the window is inactive.
So far, so good.

But sometimes the window is inactive, but still visible, because only non-fullscreen windows are in front of it.
In this case _GDIPlus_BitmapGetPixel is used and the flashing is on.

So I either need a solution to identify this special case (inactive, but visible) or some improvement of the function
above to get rid of the flashing...

Any ideas?



 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...