能不能给个思路,怎么比较两个图形是否一样。谢谢!

解决方案 »

  1.   

    这是我判断2幅图片是否相同的代码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.   

    最简单的思路如下:
    1.判断当前屏幕大小.主要有人用的是800*600,1024*768.
    2.做2个记录文件.分别记录800*600或1024*768时,某一部份出现的色彩为某个图形.配合CPU非常快的速度进行截色对比.
    搞定
      

  3.   

    去看吧~
    这个是制作教程
    http://www.enet.com.cn/eschool/inforcenter/A20041221374105_1.html
      

  4.   

    我也在做,楼主有兴趣可一起研究
    [email protected]
      

  5.   

    这是我写的程序,不是靠截屏比较图片的,而是直接读写内存。
    Http://freewebs.com/52pan/QQllkTool.exe楼主有兴趣可与我联系。
    [email protected]