请问如何得到鼠标所在屏幕那一点的RGB值?

xiaoxiao_xiao 2002-06-14 06:23:56
请问如何得到鼠标所在屏幕那一点的RGB值?
...全文
182 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaoxingchi 2002-06-15
  • 打赏
  • 举报
回复
BCB_FANS

我试了,完全可以啊!
bcb_fans 2002-06-15
  • 打赏
  • 举报
回复
我没有用过zhuxud(圣东方) 的代码,不过它利用GetDesktopWindow函数,要是
鼠标在程序窗口上,你怎么办??? 所以我用WindowFromPoint函数得到鼠标底下的窗口,不知对否???
linyin 2002-06-15
  • 打赏
  • 举报
回复
R := Color and $ff;
G := (Color and $ff00) shr 8;
B := (Color and $ff0000) shr 16;
取出RGB的值
nne998 2002-06-15
  • 打赏
  • 举报
回复
同意 zhuxud(圣东方) ,但可以更简单:handle 用 0就行了,

或者 hdc:=GetDC(0);
Billy_Chen28 2002-06-14
  • 打赏
  • 举报
回复
GetRValue,GetGValue,GetBValue, 返回颜色的R,G, B值,
bcb_fans 2002-06-14
  • 打赏
  • 举报
回复
很容易啊,看下面代码:

TPoint CurPos,WinCurPos;
TColor MouseColor;
TRect WinRect;
COLORREF CurPixel;
int RV,GV,BV;
HWND WindowHandle;

GetCursorPos(&CurPos);
WindowHandle=WindowFromPoint(CurPos);

// Get Position
GetWindowRect(WindowHandle,&WinRect);
WinCurPos.x=CurPos.x - WinRect.Left;
WinCurPos.y=CurPos.y - WinRect.Top;

// Get Color
CurPixel=GetPixel(GetWindowDC(WindowHandle),WinCurPos.x,WinCurPos.y);

MouseColor=(TColor)CurPixel;

RV=GetRValue(CurPixel);
GV=GetGValue(CurPixel);
BV=GetBValue(CurPixel);
东方小黑 2002-06-14
  • 打赏
  • 举报
回复
procedure TForm1.Timer1Timer(Sender: TObject);
var mousepos:tpoint;
var handle:hwnd;
var color:tcolor;
var dc:hdc;
begin
getcursorpos(mousepos);
handle:=getdesktopwindow;
dc:=getwindowdc(handle);
color:=getpixel(dc,mousepos.x,mousepos.y);
label1.color:=rgb(getrvalue(color),getgvalue(color),getbvalue(color));
releasedc(handle,dc);
end;
把timer控件的interval值改小一些,效果就可以了
shawy0282 2002-06-14
  • 打赏
  • 举报
回复
屏幕取色DELPHI源码
http://www.csdn.net/cnshare/soft/openfile.asp?kind=1&id=5441

5,386

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧