如何获取屏幕上某个点的像素值呢?

(1)获取屏幕窗体的句柄

hdc=GetDC(NULL);

(2)获取颜色值

mc=GetPixel(hdc);

(3)跟踪显示颜色值的完整代码

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  HWND hs;
  hs=GetTopWindow(NULL);

  HDC hdc;
  hdc=GetDC(NULL);
  COLORREF mc;
  mc=0;

  int mx,my;
          TPoint mp;
          ::GetCursorPos(&mp);
           mx=mp.x;
           my=mp.y;

  mc=GetPixel(
    hdc,    // handle of device context
    mx,    // x-coordinate of pixel
    my     // y-coordinate of pixel
   );
  int cc;
  cc=1;
  Form1->Caption=AnsiString(mc);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
  Button1->Click();
}
//---------------------------------------------------------------------------
 

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐