API函数声明自己用API函数浏览器找
dim pt as POINT
dim hWnd as LONG
dim hDC as LONG
dim color1 as long
pt.x=10:pt.y=200
hWnd=WindowFromPoint(pt)
hDC=GetDC(hWnd)
ScreenToClient(hWnd,pt)
color1=GetPixel(hDC,pt.x,pt.y)
关于模糊比较,一下算法只是我个人的想法,并非正规算法,但我觉得比较可行
函数的返回值是一个平均色差,你可以设定返回值小于某个限定值,则为相同颜色。
function compareColor(color1 as long,color2 as long) as double
dim red1,green1,blue1,red2,green2,blue2
red1=color1 and &hff
geen1=cint(color1/&h100) and &hff
blue1=cint(color1/&h10000) and &hff
red2=color2 and &hff
geen2=cint(color2/&h100) and &hff
blue2=cint(color2/&h10000) and &hff
compareColor=(((red1-red2)^2+(green1-green2)^2+(blue1-blue2)^2)/3)^0.5
end function
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Sub Command1_Click()
Me.ScaleMode = 3
PSet (100, 100), vbBlue 'SET COLOR
PSet (100, 50), vbBlue
PSet (50, 50), vbRed
MsgBox Hex(GetPixel(Me.hdc, 100, 100)) 'VBBLUE
MsgBox Hex(GetPixel(Me.hdc, 50, 50)) 'VBRED
MsgBox GetPixel(Me.hdc, 50, 50) = GetPixel(Me.hdc, 100, 50) 'DIFFERENT COLOR
MsgBox GetPixel(Me.hdc, 100, 100) = GetPixel(Me.hdc, 100, 50) ' SAME COLOR
End Sub
VB声明
Declare Function GetPixel Lib "gdi32" Alias "GetPixel" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
说明
在指定的设备场景中取得一个像素的RGB值
返回值
Long,指定点的RGB颜色。如指定的点位于设备场景的剪切区之外,则返回CLR_INVALID
参数表
参数 类型及说明
hdc Long,一个设备场景的句柄
x,y Long,逻辑坐标中要检查的点