[轉] 自訂取色函數

來源:互聯網
上載者:User

標籤:

AHK官網中文論壇挖來的擷取顏色函數:

GetColor() ;滑鼠下顏色
GetColor(7,7) ;指定座標的顏色
GetColor(7,7,7,7) ;指定範圍,將返回以高度為軸的二級對象。

克服內建取色命令的以下缺點:
在毛玻璃下延遲嚴重。
批量取色效率低下。

 

GetColor(x:="",y:="",w:=1,h:=1){ ;取色    static pt    pt?"":(DllCall("GetModuleHandle","str","gdiplus","UPtr"),VarSetCapacity(i,A_PtrSize=8?24:16,0),i:=Chr(1)            ,DllCall("gdiplus\GdiplusStartup","UPtr*",pt,"UPtr",&i,"UPtr",0))    ,(x="")?GetCursorPos(x,y):""    ,d:=DllCall("CreateCompatibleDC","Uint",0),VarSetCapacity(b,40,0),NumPut(w,b,4,"uint")    ,NumPut(h,b,8,"uint"),NumPut(40,b,0,"uint"),NumPut(1,b,12,"ushort"),NumPut(0,b,16,"uInt"),NumPut(32,b,14,"ushort")    ,m:=DllCall("CreateDIBSection","UPtr",d,"UPtr",&b,"uint",0,"UPtr*",0,"UPtr",0,"uint",0,"UPtr")    ,o:=DllCall("SelectObject","UPtr",d,"UPtr",m)    ,DllCall("BitBlt","UPtr",d,"int",0,"int",0,"int",w,"int",h,"UPtr",i:=DllCall("GetDC","UPtr",0),"int",x,"int",y,"uint",0x00CC0020)    ,DllCall("ReleaseDC","UPtr",0,"UPtr",i)    ,DllCall("gdiplus\GdipCreateBitmapFromHBITMAP","UPtr",m,"UPtr",Palette,"UPtr*",p)    ,DllCall("SelectObject","UPtr",d,"UPtr",o),DllCall("DeleteObject","UPtr",m)    ,DllCall("DeleteDC","UPtr",i),DllCall("DeleteDC","UPtr",d),VarSetCapacity(t,16)    ,NumPut(0,t,0,"uint"),NumPut(0,t,4,"uint"),NumPut(w,t,8,"uint"),NumPut(h,t,12,"uint")    ,VarSetCapacity(b,16+2*A_PtrSize,0),DllCall("Gdiplus\GdipBitmapLockBits","UPtr",p,"UPtr",&t,"uint",3,"int",0x26200a,"UPtr",&b)    ,e:= NumGet(b,8,"Int"),u:=NumGet(b,16,"UPtr"),r:=A_FormatInteger    SetFormat,IntegerFast,hex    if (w>1 or h>1)    {        f:=[]        Loop,%h%        {            f[A_Index]:=j:=[],s:=(A_Index-1)*e            Loop,%w%                j[A_Index]:=NumGet(u+0,((A_Index-1)*4)+s,"UInt")  & 0x00ffffff ""        }    }    else f:=NumGet(u+0,0,"UInt") & 0x00ffffff  ""    SetFormat,IntegerFast,%r%    DllCall("Gdiplus\GdipBitmapUnlockBits","UPtr",p,"UPtr",0)    DllCall("gdiplus\GdipDisposeImage", "uint", p)    return f}

 

原地址:http://ahkscript.org/boards/viewtopic.php?f=28&t=5023

[轉] 自訂取色函數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.