此找色统计的补充完善示例返回结果大概如下:
指定坐标范围内色值出现的次数:6262
指定坐标范围内的总像素:172480
耗时:270.866400 ms
以下示例是我自己补充和测试的:
; 用法:获取多个颜色前先无参数截屏,坐标相对屏幕,返回颜色为RGB格式 ; 快速获取多个颜色 By FeiYue CoordMode Pixel SetBatchLines -1 CoordMode Mouse ;-- 下面是速度测试(在我的电脑上差了2000倍) 以下为:原版示例保留 ; n:=30 * 1 ; t1:=A_TickCount ; SetBatchLines, -1 ; Loop, % n ; PixelGetColor, color, 100, 10, RGB ; t2:=A_TickCount ; MsgBox,4096,, % "PixelGetColor 结果:" color "`n耗时:" (t2-t1)/n " ms" ; ; n:=30 * 1 ; t1:=A_TickCount ; SetBatchLines, -1 ; FastPixelGetColor() ; Loop, % n ; color:=FastPixelGetColor(100, 10) ; t2:=A_TickCount ; MsgBox,4096,, % "FastPixelGetColor 结果:" color "`n耗时:" (t2-t1)/n " ms" ; 下面这个范围好像只能从坐标0,0开始,忘记了。【待验证】 n := 0 计时() ; x1 := 2, y1 := 835, x2 := 75, y2 := 915 x1 := 646, y1 := 321, w := 616, h := 280 ; x1 := 0 ; y1 := 0 ; x2 := 148 ; y2 := 65 arr:=[] FastPixelGetColor() Loop %w% { Loop %h% color:=FastPixelGetColor(x1, y1+A_Index), arr[color] := arr[color] ? arr[color]+1 : 1, n++ x1++ } MsgBox % "指定坐标范围内色值出现的次数:" arr[0xFFFFFF] "`n指定坐标范围内的总像素:" n "`n耗时:" 计时() " ms" ; MsgBox % "你所指定坐标范围内,色值出现的次数:" arr[0xFE8276] ; 键值总数量 MsgBox % "共捕获颜色数量:" arr.count() Return ; 按F1可以截图你想要的范围 F1:: if (onoff := !onoff) { 第一个框 := new HighlightOutline(, 178) MouseGetPos, x1, y1 Tip("x1和y1坐标已经记录") } else { MouseGetPos, x2, y2 第一个框.show(x1, y1, x2, y2) Clipboard := "x1 := " x1 ", y1 := " y1 ", w := " x2-x1 ", h := " y2-y1 Tip("坐标已存入剪贴板中") SetTimer 选框延时关闭, -1200 } Return ; w := x2-x1, h := y2-y1 Tip(s:="", Period:="") { SetTimer %A_ThisFunc%, % s="" ? "Off" : "-" (Period="" ? 1500 : Period) ToolTip %s%, , , 17 } 选框延时关闭: x1 := y1 := x2 := y2 := "" 第一个框.Hide() Return ;-- 获取多个颜色前先无参数截屏,坐标相对屏幕,返回颜色为RGB格式 By FeiYue FastPixelGetColor(x="", y="") { Static if (x!="" and y!="") return (!Scan0 or x<zx or x>=zx+zw or y<zy or y>=zy+zh) ? "0xFFFFFF" : Format("0x{:06X}",NumGet(Scan0+(y-zy)*Stride+(x-zx)*4,"uint")&0xFFFFFF) bch:=A_BatchLines, cri:=A_IsCritical SetBatchLines -1 Critical ; 获取屏幕范围 SysGet, zx, 76 SysGet, zy, 77 SysGet, zw, 78 SysGet, zh, 79 if (zw!=oldzw or zh!=oldzh or !mDC or !hBM) oldzw:=zw, oldzh:=zh ; 清理旧的内存图像 , DllCall("SelectObject", "Ptr",mDC, "Ptr",oBM) , DllCall("DeleteDC", "Ptr",mDC) , DllCall("DeleteObject", "Ptr",hBM) ; 创建新的内存图像 , NumPut(VarSetCapacity(bi, 40, 0), bi) , NumPut(zw, bi, 4), NumPut(-zh, bi, 8) , NumPut(bpp:=32, NumPut(1, bi, 12, "UShort"), 0, "Ushort") , NumPut(0, bi, 16), Stride:=(zw*bpp+31)//32*4 , hBM:=DllCall("CreateDIBSection", "Ptr",0, "Ptr",&bi, "Ptr",0, "PtrP",Scan0:=0, "Ptr",0, "Ptr",0) , mDC:=DllCall("CreateCompatibleDC", "Ptr",0) , oBM:=DllCall("SelectObject", "Ptr",mDC, "Ptr",hBM) ; 截屏到内存图像 hDC:=DllCall("GetDC", "Ptr",0) , DllCall("BitBlt", "Ptr",mDC, "int",0, "int",0, "int",zw, "int",zh, "Ptr",hDC, "int",zx, "int",zy, "uint", 0x40000000|0x00CC0020) , DllCall("ReleaseDC", "Ptr",0, "Ptr",hDC) Critical, %cri% SetBatchLines, %bch% } 计时() { Static if 开始= DllCall("QueryPerformanceFrequency", "Int64*", 频率), DllCall("QueryPerformanceCounter", "Int64*", 开始) else DllCall("QueryPerformanceCounter", "Int64*", 结束), 耗时:=(结束 - 开始)/频率*1000, 开始:="" Return 耗时 } class HighlightOutline { __New(Color="Red", Transparent=255) { Loop 4 { Gui New, -Caption +AlwaysOnTop +ToolWindow HWNDhwnd -DPIScale +E0x20 +E0x00080000 Gui Color, %Color% DllCall("SetLayeredWindowAttributes", "Ptr", this[A_Index] := hwnd, "Uint", 0, "Uchar", Transparent, "int", 2) } this.top := this[1] , this.right := this[2] , this.bottom := this[3] , this.left := this[4] Gui Gui_Cheek_Number%A_DefaultGui%: Default } Show(x1, y1, x2, y2, b=3) { Try Gui % this[1] ":Show", % "NA x" x1-b " y" y1-b " w" x2-x1+b*2 " h" b Try Gui % this[2] ":Show", % "NA x" x2 " y" y1 " w" b " h" y2-y1 Try Gui % this[3] ":Show", % "NA x" x1-b " y" y2 " w" x2-x1+2*b " h" b Try Gui % this[4] ":Show", % "NA x" x1-b " y" y1 " w" b " h" y2-y1 } Hide() { Loop 4 Gui % this[A_Index] ": Hide" } Destroy() { Loop 4 Gui % this[A_Index] ": Destroy" } }
声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。
评论(0)