獲取窗體顏色

2021-08-29 07:38:22 字數 1182 閱讀 1180

//獲取窗體dc 

cdc *pdc = getdc();

//獲取顏色值

colorref cr = pdc->getpixel(point);

//提取rgb分量

m_nr = getrvalue(cr);//r值

m_ng = getgvalue(cr);//g值

m_nb = getbvalue(cr);//b值

getdc()函式

getpixel 取畫素點

getpixel取窗體顏色值 !!!!

getcursorpos 360百科

最後應該是要釋放掉  releasedc

完整delphi例項:

delphi如何獲取滑鼠當前位置顏色

procedure tform1.getcolor(hdl: thandle);

var dc: hdc;

pt: tpoint;

cr: colorref;

r, g, b: byte;

rlt: integer;

begin

//hdl=0表示:得到整個螢幕的顯示裝置上下文環境的控制代碼

dc:= getdc(hdl);

//檢取游標的位置,以螢幕座標表示

getcursorpos(pt);

//用getdevicecaps來判斷裝置是否支援getpixel

//檢索指定座標點的畫素的rgb顏色值

cr:= getpixel(dc, pt.x, pt.y);

if cr = clr_invalid then //clr_invalid

mmo1.lines.add('指定的畫素點在當前剪輯區之外')

else

begin

r:= getrvalue(cr);//r值

g:= getgvalue(cr);//g值

b:= getbvalue(cr);//b值

mmo1.lines.add('r:'+inttostr(r)+';g:'+inttostr(g)+';b:'+inttostr(b));

rlt:= releasedc(handle, dc);

end;

end;

關於getdc與getwindowdc

WPF窗體更換背景顏色

窗體介面如下 介面設計 如下 透明度 紅色 綠色 藍色 public override void endinit public static color selectcolor private void a valuechanged object sender,routedpropertychang...

提示整個窗體的文字顏色

nodes i onblur function this.style.fontsize 0.7em this.style.color 000 this.style.height 14px this.style.margintop 1px nodes document.getelementsbytag...

滑鼠獲取窗體控制代碼

通過滑鼠座標獲取窗體控制代碼 cpoint lppoint getcursorpos lppoint 得到當前座標 hwnd hwnd 定義窗體控制代碼 hwnd windowfrompoint lppoint char formtitle max path char classname max p...