How can I find the colour of any pixel on the scre

2019-07-24 14:59发布

问题:

I usually program in VB6 but but I believe with that I might be restricted to details within the active form. I also have codegear 2009 with c++ and delphi, that I got from a mate but I only have a little experience with Delphi and none at all with c++ but at least I have them if one of those program need to be used to acheive what I'm trying to do. I want to be able to do something like

IF pixelVar(x,y) = 'Red' ( or 'RGBvalue or whatever the correct colour representation)
THEN
    do something
END IF

I want to write a program to keep poker hand statistics and want the program to run while Im playing in the poker client program, auto recognizing the cards by pixel colour and position and entering them into the database. I think that if I can get easy access to pixel info it wouldn't be too difficult working out patterns to identify the number and suit of cards. Any help would be enormous. Thanks.

回答1:

Use GetDC() with its hWnd parameter set to 0 to get an HDC handle for the screen, then use GetPixel() to get a COLORREF of the pixel at the desired screen coordinates, and then finally use GetRValue(), GetGValue(), and GetBValue() to split the COLORREF into its Red, Green, and Blue values.