[Lib] GetColor() - 取色及范围取色

许多实用脚本和封装函数, 可以让您编写脚本更加便捷高效

Moderators: tmplinshi, arcticir

arcticir
Posts: 694
Joined: 17 Nov 2013, 11:32

[Lib] GetColor() - 取色及范围取色

31 Oct 2014, 06:17

GetColor() ;鼠标下
GetColor(7,7) ;指定座标
GetColor(7,7,7,7) ;指定范围,将返回以高度为轴的二级对象。


克服内置取色命令的以下缺点:
在毛玻璃下延迟严重。
批量取色效率低下。

Code: Select all

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
}
User avatar
RobertL
Posts: 546
Joined: 18 Jan 2014, 01:14
Location: China

Re: [Lib] GetColor() - 取色及范围取色

31 Oct 2014, 22:05

震惊,厉害!

返回以高度为轴的二级对象啥意思?

代码紧凑,但不了解结构、流程,看着费劲..

貌似主要为GDIP功能,不知道用GDIP库,能否拼凑出来,感觉会直观点..
我为人人,人人为己?
arcticir
Posts: 694
Joined: 17 Nov 2013, 11:32

Re: [Lib] GetColor() - 取色及范围取色

01 Nov 2014, 05:59

看DllCall就行,结构没啥意义。
对象是这种:
F[H][W]=0X232323
User avatar
RobertL
Posts: 546
Joined: 18 Jan 2014, 01:14
Location: China

Re: [Lib] GetColor() - 取色及范围取色

03 Nov 2014, 08:10

哦,看着晕..还是封装了好用..估计按dll能找出函数名来。
我为人人,人人为己?
autu
Posts: 17
Joined: 04 Apr 2015, 11:09

Re: [Lib] GetColor() - 取色及范围取色

27 Apr 2015, 07:46

这个很不错 借用了 呵呵
vasili111
Posts: 747
Joined: 21 Jan 2014, 02:04
Location: Georgia

Re: [Lib] GetColor() - 取色及范围取色

27 Apr 2015, 08:21

If I correctly understand (I used google translate) that lib is high performance version of PixelGetColor. I think it is very useful lib.
But I don't understand what GetColor (7,7,7,7) is doing. It will return the mean color of region or what?
Please also post that script at english forums.
DRAKON-AutoHotkey: Visual programming for AutoHotkey.

Return to “脚本函数”

Who is online

Users browsing this forum: No registered users and 27 guests