实现效果:- PutAttachment "c:\图片", "*.bmp"'释放图片到本地,同时解决使用附件路径找图找不到的Bug
- 数组 = lib.文件.遍历指定目录下所有文件名("C:\图片")'遍历所有图片名称
- For i = 0 To UBound(数组) - 1
- 数组(i)=数组(i)&"|"&bmp尺寸("C:\图片\"&数组(i))'获取图片的尺寸
- TracePrint 数组(i)
- Next
- Call 找图("1.bmp")'调用sub找图
- Sub 找图(图名)
- FindPic 0,0,1024,768,"C:\图片\"&图名,0.9,intX,intY'找图命令
- If intX > 0 And intY > 0 Then '找到图片判断
- TracePrint intx & "," & inty'图片左上角坐标
- 查询 = Filter(数组, 图名)'通过Filter返回包含图片名称的对应内容
- TracePrint intx+ (Split(查询(0),"|")(1)/2)&","&inty+(Split(查询(0),"|")(2)/2)'intx,inty加上偏移量(图片长/2,图片高/2)
- End If
- End Sub
- Function bmp尺寸(bmp_file)
- Set ado = CreateObject("ADODB.Stream")
- ado.Type = 1
- ado.Open
- ado.LoadFromFile bmp_file
- ado.Read(2)
- ado.Read(12)
- width1 = CByte(AscB(ado.Read(1)))
- width2 = CByte(AscB(ado.Read(1)))
- width3 = CByte(AscB(ado.Read(1)))
- width4 = CByte(AscB(ado.Read(1)))
- width = width4 * 256 * 256 * 256 + width3 * 256 * 256 + width2 * 256 + width1
- height1 = CByte(AscB(ado.Read(1)))
- height2 = CByte(AscB(ado.Read(1)))
- height3 = CByte(AscB(ado.Read(1)))
- height4 = CByte(AscB(ado.Read(1)))
- height = height4 * 256 * 256 * 256 + height3 * 256 * 256 + height2 * 256 + height1
- ado.Close
- bmp尺寸 = width &"|"& height
- End Function
复制代码PutAttachment "c:\图片", "*.bmp"
数组 = lib.文件.遍历指定目录下所有文件名("C:\图片")
For i = 0 To UBound(数组) - 1
数组(i)=数组(i)&"|"&bmp尺寸("C:\图片\"&数组(i))
TracePrint 数组(i)
Next
Call 找图("1.bmp|2.bmp|3.bmp")'大漠找多图写法
Sub 找图(图名)
dm_ret = dm.FindPic(0,0,2000,2000,图名,"000000",0.9,0,intX,intY)
If intX >= 0 and intY >= 0 Then
分割 = split(图名, "|")(dm_ret)'大漠找到会返回图片序号到dm_ret变量,利用其作为下标分割出对应图片名称
TracePrint intx & "," & inty
查询 = Filter(数组, 分割)
TracePrint intx+ (Split(查询(0),"|")(1)/2)&","&inty+(Split(查询(0),"|")(2)/2)
End If
End Sub
Function bmp尺寸(bmp_file)
Set ado = CreateObject("ADODB.Stream")
ado.Type = 1
ado.Open
ado.LoadFromFile bmp_file
ado.Read(2)
ado.Read(12)
width1 = CByte(AscB(ado.Read(1)))
width2 = CByte(AscB(ado.Read(1)))
width3 = CByte(AscB(ado.Read(1)))
width4 = CByte(AscB(ado.Read(1)))
width = width4 * 256 * 256 * 256 + width3 * 256 * 256 + width2 * 256 + width1
height1 = CByte(AscB(ado.Read(1)))
height2 = CByte(AscB(ado.Read(1)))
height3 = CByte(AscB(ado.Read(1)))
height4 = CByte(AscB(ado.Read(1)))
height = height4 * 256 * 256 * 256 + height3 * 256 * 256 + height2 * 256 + height1
ado.Close
bmp尺寸 = width &"|"& height
End Function