我想监视另一个程序的动作。查找内存地址。发现找不到规律。只能从抓图对比了。但是不知道怎样才能对比2张不同的图片?谁有这方面资料可以给出吗?十分感谢!

解决方案 »

  1.   

    我有一段代码。大家能给我解释一下吗?
    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
      

  2.   

    这个是直接解释bmp文件格式,然后比较的
      

  3.   

    http://blog.csdn.net/terry6394/archive/2004/10/23/148583.aspx1024X768
      

  4.   

    算法问题了1 如果有现成的函数,可以直接对 整个BMP 2进制数组 hash,或者直接对数组进行比较2 或者象素比较,牵扯到查找了.可以用折半查找比较,算法的效率问题自己研究数据结构还是取象素比较比较快,但是不要顺序比较
      

  5.   

    dsclub这个id很熟悉啊,莫非就是那个csdn helper的作者?