我想监视另一个程序的动作。查找内存地址。发现找不到规律。只能从抓图对比了。但是不知道怎样才能对比2张不同的图片?谁有这方面资料可以给出吗?十分感谢!
解决方案 »
- Picture1,y轴的方向问题
- 关于 ListView 的问题(在线等,急,急!!!)
- 关于DataCombo控件的的下超难问题,高救命呀!!!!!
- 请教一个SQL查询问题
- treeview的打印问题,请各位大侠帮帮忙
- ACCESS可以建视图吗?
- 我想用vb建立一个sql server的数据库,但不知应该怎么做,请各位高手踊跃讨论,参加有分
- 请问ASP中的参数如何传递到VB程序中!在线等待
- 哪个晓得么样调出打印机设置的窗口,感谢万分!
- 我最近在做一个关于我们毕业纪念的光盘,想在找个好的动画在光盘自动运行时执行
- 请问模块(Module)的数量对程序有什么影响?
- VB为何在编辑代码时,怎么不能使用鼠标滚动键呢?
Option Explicit
Private Type BITMAPINFOHEADER '40 bytes
biSize As Long
biWidth As Long
biHeight As Long
biPlanes As Integer
biBitCount As Integer
biCompression As Long
biSizeImage As Long
biXPelsPerMeter As Long
biYPelsPerMeter As Long
biClrUsed As Long
biClrImportant As Long
End TypePrivate Type RGBQUAD
rgbBlue As Byte
rgbGreen As Byte
rgbRed As Byte
rgbReserved As Byte
End TypePrivate Type BITMAPINFO
bmiHeader As BITMAPINFOHEADER
bmiColors As RGBQUAD
End Type
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As IntegerPrivate Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC 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 dwRop As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function CreateDIBSection Lib "gdi32" (ByVal hdc As Long, pBitmapInfo As BITMAPINFO, ByVal un As Long, ByVal lplpVoid As Long, ByVal handle As Long, ByVal dw As Long) As LongPrivate Const BI_RGB = 0&
Private Const DIB_RGB_COLORS = 0
Private Const IMAGE_BITMAP As Long = 0
Private Const LR_LOADFROMFILE As Long = &H10
Private Const LR_CREATEDIBSECTION As Long = &H2000
Private Const LR_DEFAULTCOLOR As Long = &H0
Private Const LR_COLOR As Long = &H2
Private Const SRCAND = &H8800C6
Private Const SRCCOPY = &HCC0020
Private Const SRCERASE = &H440328
Private Const SRCPAINT = &HEE0086
Private Const SRCINVERT = &H660046Private Declare Function timeGetTime Lib "winmm.dll" () As LongPrivate Declare Function GetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
Private Declare Function SetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
Private Declare Function GetDC Lib "user32.dll" (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 Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As LongPrivate Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Private Declare Function APIBeep Lib "kernel32" Alias "Beep" (ByVal dwFreq As Long, ByVal dwDuration As Long) As LongPrivate Const MOUSEEVENTF_MOVE = &H1 ' mouse move
Private Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down
Private Const MOUSEEVENTF_LEFTUP = &H4 ' left button up
Private Const MOUSEEVENTF_ABSOLUTE = &H8000 ' absolute moveConst Button_Width = 31 '按钮宽度(px)
Const Button_Height = 35 '按钮高度(px)
Const Button_X = 19 '按钮水平个数
Const Button_Y = 11 '按钮垂直个数
Const Button_Left = 14 '起始按钮的x
Const Button_Top = 181 '起始按钮的y
Function GetDiff(Pic1 As PictureBox, Pic2 As PictureBox) As Boolean
Dim i As Long, j As Long
Dim iBitmap As Long, iDC As Long
Dim i2Bitmap As Long, i2DC As Long
Dim XWidth As Long, YHeight As Long
Dim hOldMap As Long
Dim bi24BitInfo As BITMAPINFO
Dim bi24Bit2Info As BITMAPINFO
Dim PicBits() As Byte
Dim Pic2Bits() As Byte
With bi24BitInfo.bmiHeader
.biBitCount = 32
.biCompression = BI_RGB
.biPlanes = 1
.biSize = Len(bi24BitInfo.bmiHeader)
.biWidth = Pic1.ScaleWidth
.biHeight = Pic1.ScaleHeight
.biSizeImage = .biWidth * 4 * .biHeight
End With
iDC = CreateCompatibleDC(0)
iBitmap = CreateDIBSection(iDC, bi24BitInfo, DIB_RGB_COLORS, ByVal 0&, ByVal 0&, ByVal 0&)
If iBitmap Then
hOldMap = SelectObject(iDC, iBitmap)
Else
DeleteObject iDC
Exit Function
End If
GetDiff = True
With bi24Bit2Info.bmiHeader
.biBitCount = 32
.biCompression = BI_RGB
.biPlanes = 1
.biSize = Len(bi24Bit2Info.bmiHeader)
.biWidth = Pic2.ScaleWidth
.biHeight = Pic2.ScaleHeight
.biSizeImage = .biWidth * 4 * .biHeight
End With
i2DC = CreateCompatibleDC(0)
i2Bitmap = CreateDIBSection(i2DC, bi24Bit2Info, DIB_RGB_COLORS, ByVal 0&, ByVal 0&, ByVal 0&)
If i2Bitmap Then
hOldMap = SelectObject(i2DC, i2Bitmap)
Else
DeleteObject i2DC
Exit Function
End If
BitBlt iDC, 0, 0, bi24BitInfo.bmiHeader.biWidth, bi24BitInfo.bmiHeader.biHeight, Pic1.hdc, 0, 0, vbSrcCopy
ReDim PicBits(1 To 4, 1 To bi24BitInfo.bmiHeader.biWidth, 1 To bi24BitInfo.bmiHeader.biHeight) As Byte
GetBitmapBits iBitmap, bi24BitInfo.bmiHeader.biSizeImage, PicBits(1, 1, 1) '将iBitmap读取到PicBits数组中
BitBlt i2DC, 0, 0, bi24Bit2Info.bmiHeader.biWidth, bi24Bit2Info.bmiHeader.biHeight, Pic2.hdc, 0, 0, vbSrcCopy
ReDim Pic2Bits(1 To 4, 1 To bi24Bit2Info.bmiHeader.biWidth, 1 To bi24Bit2Info.bmiHeader.biHeight) As Byte
GetBitmapBits i2Bitmap, bi24Bit2Info.bmiHeader.biSizeImage, Pic2Bits(1, 1, 1) '将i2Bitmap读取到Pic2Bits数组中
XWidth = -1: YHeight = -1
For i = 1 To bi24Bit2Info.bmiHeader.biWidth
For j = 1 To bi24Bit2Info.bmiHeader.biHeight
If Abs(CLng(PicBits(1, i, j)) - CLng(Pic2Bits(1, i, j))) > 10 Or Abs(CLng(PicBits(2, i, j)) - CLng(Pic2Bits(2, i, j))) > 10 _
Or Abs(CLng(PicBits(3, i, j)) - CLng(Pic2Bits(3, i, j))) > 10 Then
XWidth = i
YHeight = j
Exit For
End If
Next j
If XWidth > -1 And YHeight > -1 Then Exit For
Next i
If XWidth > -1 And YHeight > -1 Then
GetDiff = False
End If
If hOldMap Then DeleteObject SelectObject(iDC, hOldMap)
If hOldMap Then DeleteObject SelectObject(i2DC, hOldMap)
DeleteObject iDC
DeleteObject i2DC
End Function