解决的方法:
1。如果你能解析bmp格式,那么,创建BMP图片,然后用LoadPicture加载到Picture中显示
2。如果你会用C++,那么用C++写一个控件,用于绘图
3。用C#或VB.net吧,处理起来相当的快速。
先截图,再提取像素在窗体上放一个PictureBox,叫PicT,ScaleMode=3,作截屏的目标。
代码如下
------------------------------
Dim RGB() As Long
Private Const SRCCOPY = &HCC0020
Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function StretchBlt Lib "gdi32" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
Private Sub Form_Load()
PicT.Height = Screen.Height
PicT.Width = Screen.Width
End Sub
'如果需要,可以直接用这个
Private Sub GetPoints(x() As Long, y() As Long)
'截屏
StretchBlt PicT.hDC, 0, 0, Screen.Width, Screen.Height, GetDC(0), 0, 0, Screen.Width, Screen.Height, SRCCOPY
'将以x的大小为准,xy坐标应配套用
ReDim RGB(UBound(x))
Dim i As Long
For i = 0 To UBound(x)
'得到点颜色,返回的是类似rgb()的数字,好像和GetPixel一样(OLE_COLOR)
RGB(i) = PicT.Point(x(i), y(i))
Next i
End Sub
---------------------------
下面是使用示例
---------------------------
Private Sub Command1_Click()
'这一块你可以用循环进行赋值,本例取3点
Dim x(2) As Long, y(2) As Long
x(0) = 50
x(1) = 100
x(2) = 300
y(0) = 50
y(1) = 100
y(2) = 300
'赋值结束,传入参数
GetPoints x(), y()
'输出结果
MsgBox RGB(0)
MsgBox RGB(1)
MsgBox RGB(2)
End Sub
PS:我只在win7里试过,xp应该也行。
rgb这么分解:
Red = (Color Mod 256)
Green = ((Color Mod 65536) \ 256)
Blue = (Color \ 65536)
'A、B点坐标设置XA = 960
YA = 540
XB = 1920
YB = 1080
'计数变量赋初值
i = 0
t = 0
Do
A = GetPixelColor(XA, YA)'获取A点颜色
TracePrint A
If A = "FFFFFF" Then
i = i + 1'为白色,则i自增1
Else
i = 0'不为白色,则i归0
End If
If i = 11 or t=60 Then
Exit do'10秒内连续11次检测都为白色或者循环耗时达到60秒,则退出循环
End If
Delay 1000'相邻两次检测的时间间隔
t=t+1
Loop
TracePrint "i=" & i
TracePrint "t=" & t
'10秒内连续11次检测都为白色,执行对应 *** 作
If i = 11 Then
Delay 50
MoveTo XB, YB
Delay 50
LeftClick 1
End If
EndScript
以上代码只是一种近似实现。由于采用的是抽样检测的方法,加之getpixelcolor这条指令较慢,因此如果对时间精度控制要求很高,则上述代码就无能为力了。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)