vb.net分区找图的简单介绍
用vb.net实现查找显示图片?
IO.Directory.GetFiles
我们提供的服务有:网站设计、成都网站制作、微信公众号开发、网站优化、网站认证、扶绥ssl等。为上千余家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的扶绥网站制作公司
获取指定目录中的所有文件,比对文件名就行了。如果包括多层子目录,需要递归
用VB如何实现按键精灵的区域找图功能
用DIB把指定区域32位图像信息CopyMemory到一个Long型数组变量
再用DIB将需要查找的图像作为32位图像载入内存为Long型数组变量
比较这两个Long型数组变量可以这样引用
lVar(x,height-y-1)'这样取得(x,y)坐标的Long颜色值,其中Height是图像高度
最后进行对比
注:用Long型变量是为了方便代码书写,也可以用Byte三维数组但是这样是不必要的
如何 用 VB 在规定的范围 找图,找色..源码
'下面是屏幕找色实例,请根据实际情况进行验证。
Option Explicit
'定义一个POINTAPI
Private Type POINTAPI
x As Long
y As Long
End Type
'定义一个找色区域
Private Type RECT
Left As Long '区域坐标x
Top As Long '区域坐标y
Right As Long '区域宽
Bottom As Long '区域高
End Type
'Windows API 声明
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function GetPixel Lib "gdi32" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long) As Long
'测试颜色函数,给定屏幕任意找色区域值,返回坐标位置
Private Function ifColor(x As RECT, ByVal color As Long) As POINTAPI
On Error Resume Next
Dim nTmpColor As Long, i As Long, j As Long
For i = x.Left To x.Left + x.Right
For j = x.Top To x.Top + x.Bottom
nTmpColor = GetPixel(GetDC(0), i, j)
If color = nTmpColor Then
ifColor.x = i
ifColor.y = j
Exit Function
End If
DoEvents
Next
Next
End Function
Private Sub Command1_Click() '全屏幕找色,时间花费较长
Dim t As POINTAPI, m As RECT
With m
.Top = 0
.Left = 0
.Bottom = Screen.Height / Screen.TwipsPerPixelY
.Right = Screen.Width / Screen.TwipsPerPixelX
End With
t = ifColor(m, 1447073)
Debug.Print t.x, t.y
End Sub
Private Sub Command2_Click() '某区域找色,时间花费少
Dim t As POINTAPI, m As RECT
With m
.Top = 300
.Left = 300
.Bottom = 100
.Right = 100
End With
t = ifColor(m, RGB(0, 125, 125))
Debug.Print t.x, t.y
End Sub
名称栏目:vb.net分区找图的简单介绍
网址分享:http://scjbc.cn/article/hiiogs.html