home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 5_2007-2008.ISO / data / Zips / Compare_tw2082779102007.psc / ImageCompare / FrmMain.frm < prev    next >
Text File  |  2007-09-11  |  20KB  |  563 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx"
  3. Begin VB.Form FrmMain 
  4.    BackColor       =   &H00FFC0C0&
  5.    Caption         =   "Compare Two Images -by Cm.Shafi"
  6.    ClientHeight    =   8895
  7.    ClientLeft      =   60
  8.    ClientTop       =   450
  9.    ClientWidth     =   12120
  10.    Icon            =   "FrmMain.frx":0000
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   8895
  13.    ScaleWidth      =   12120
  14.    StartUpPosition =   3  'Windows Default
  15.    Begin VB.PictureBox Picture1 
  16.       Appearance      =   0  'Flat
  17.       BackColor       =   &H00FFC0C0&
  18.       BorderStyle     =   0  'None
  19.       ForeColor       =   &H80000008&
  20.       Height          =   1000
  21.       Left            =   0
  22.       ScaleHeight     =   1005
  23.       ScaleWidth      =   12015
  24.       TabIndex        =   8
  25.       Top             =   5400
  26.       Width           =   12015
  27.       Begin VB.CommandButton CmdClear 
  28.          BackColor       =   &H00FFC0C0&
  29.          Caption         =   "Clear all"
  30.          BeginProperty Font 
  31.             Name            =   "MS Sans Serif"
  32.             Size            =   8.25
  33.             Charset         =   0
  34.             Weight          =   700
  35.             Underline       =   0   'False
  36.             Italic          =   0   'False
  37.             Strikethrough   =   0   'False
  38.          EndProperty
  39.          Height          =   495
  40.          Left            =   0
  41.          TabIndex        =   17
  42.          Top             =   0
  43.          Width           =   975
  44.       End
  45.       Begin VB.CommandButton CmdAction 
  46.          BackColor       =   &H00FFC0C0&
  47.          Caption         =   "Compare Both Images"
  48.          BeginProperty Font 
  49.             Name            =   "MS Sans Serif"
  50.             Size            =   8.25
  51.             Charset         =   0
  52.             Weight          =   700
  53.             Underline       =   0   'False
  54.             Italic          =   0   'False
  55.             Strikethrough   =   0   'False
  56.          EndProperty
  57.          Height          =   495
  58.          Left            =   4200
  59.          TabIndex        =   13
  60.          Top             =   0
  61.          Width           =   2295
  62.       End
  63.       Begin VB.CheckBox Check1 
  64.          BackColor       =   &H00FFC0C0&
  65.          Caption         =   "Case Sensitive"
  66.          BeginProperty Font 
  67.             Name            =   "MS Sans Serif"
  68.             Size            =   8.25
  69.             Charset         =   0
  70.             Weight          =   700
  71.             Underline       =   0   'False
  72.             Italic          =   0   'False
  73.             Strikethrough   =   0   'False
  74.          EndProperty
  75.          Height          =   375
  76.          Left            =   4560
  77.          TabIndex        =   12
  78.          Top             =   600
  79.          Width           =   1695
  80.       End
  81.       Begin VB.CommandButton CmdRefresh 
  82.          BackColor       =   &H00FFC0C0&
  83.          Caption         =   "Clear Result"
  84.          BeginProperty Font 
  85.             Name            =   "MS Sans Serif"
  86.             Size            =   8.25
  87.             Charset         =   0
  88.             Weight          =   700
  89.             Underline       =   0   'False
  90.             Italic          =   0   'False
  91.             Strikethrough   =   0   'False
  92.          EndProperty
  93.          Height          =   495
  94.          Left            =   10920
  95.          TabIndex        =   11
  96.          Top             =   0
  97.          Width           =   975
  98.       End
  99.       Begin VB.CommandButton CmdBrowse1 
  100.          BackColor       =   &H00FFC0C0&
  101.          Caption         =   "Browse Image 1"
  102.          BeginProperty Font 
  103.             Name            =   "MS Sans Serif"
  104.             Size            =   8.25
  105.             Charset         =   0
  106.             Weight          =   700
  107.             Underline       =   0   'False
  108.             Italic          =   0   'False
  109.             Strikethrough   =   0   'False
  110.          EndProperty
  111.          Height          =   375
  112.          Left            =   1320
  113.          TabIndex        =   10
  114.          Top             =   0
  115.          Width           =   2535
  116.       End
  117.       Begin VB.CommandButton CmdBrowse2 
  118.          BackColor       =   &H00FFC0C0&
  119.          Caption         =   "Browse Image 2"
  120.          BeginProperty Font 
  121.             Name            =   "MS Sans Serif"
  122.             Size            =   8.25
  123.             Charset         =   0
  124.             Weight          =   700
  125.             Underline       =   0   'False
  126.             Italic          =   0   'False
  127.             Strikethrough   =   0   'False
  128.          EndProperty
  129.          Height          =   375
  130.          Left            =   7680
  131.          TabIndex        =   9
  132.          Top             =   0
  133.          Width           =   2535
  134.       End
  135.       Begin VB.Label Label3 
  136.          AutoSize        =   -1  'True
  137.          BackStyle       =   0  'Transparent
  138.          Caption         =   "Result:-"
  139.          BeginProperty Font 
  140.             Name            =   "MS Sans Serif"
  141.             Size            =   12
  142.             Charset         =   0
  143.             Weight          =   700
  144.             Underline       =   0   'False
  145.             Italic          =   0   'False
  146.             Strikethrough   =   0   'False
  147.          EndProperty
  148.          ForeColor       =   &H000000C0&
  149.          Height          =   300
  150.          Left            =   0
  151.          TabIndex        =   16
  152.          Top             =   660
  153.          Width           =   960
  154.       End
  155.       Begin VB.Shape Shape1 
  156.          Height          =   375
  157.          Left            =   0
  158.          Top             =   600
  159.          Width           =   12015
  160.       End
  161.       Begin VB.Label Label1 
  162.          Alignment       =   2  'Center
  163.          AutoSize        =   -1  'True
  164.          BackStyle       =   0  'Transparent
  165.          Caption         =   "Match:"
  166.          BeginProperty Font 
  167.             Name            =   "MS Sans Serif"
  168.             Size            =   12
  169.             Charset         =   0
  170.             Weight          =   700
  171.             Underline       =   0   'False
  172.             Italic          =   0   'False
  173.             Strikethrough   =   0   'False
  174.          EndProperty
  175.          ForeColor       =   &H000000C0&
  176.          Height          =   300
  177.          Left            =   1920
  178.          TabIndex        =   15
  179.          Top             =   660
  180.          Width           =   840
  181.       End
  182.       Begin VB.Label Label2 
  183.          Alignment       =   2  'Center
  184.          AutoSize        =   -1  'True
  185.          BackStyle       =   0  'Transparent
  186.          Caption         =   "Not Match:"
  187.          BeginProperty Font 
  188.             Name            =   "MS Sans Serif"
  189.             Size            =   12
  190.             Charset         =   0
  191.             Weight          =   700
  192.             Underline       =   0   'False
  193.             Italic          =   0   'False
  194.             Strikethrough   =   0   'False
  195.          EndProperty
  196.          ForeColor       =   &H000000C0&
  197.          Height          =   300
  198.          Left            =   8400
  199.          TabIndex        =   14
  200.          Top             =   660
  201.          Width           =   1335
  202.       End
  203.    End
  204.    Begin VB.PictureBox PicBk 
  205.       Height          =   5055
  206.       Index           =   3
  207.       Left            =   6120
  208.       ScaleHeight     =   4995
  209.       ScaleWidth      =   5100
  210.       TabIndex        =   3
  211.       Top             =   6600
  212.       Width           =   5160
  213.       Begin VB.PictureBox Pic 
  214.          Appearance      =   0  'Flat
  215.          AutoSize        =   -1  'True
  216.          BackColor       =   &H80000005&
  217.          ForeColor       =   &H80000008&
  218.          Height          =   1935
  219.          Index           =   3
  220.          Left            =   1680
  221.          MouseIcon       =   "FrmMain.frx":030A
  222.          MousePointer    =   99  'Custom
  223.          ScaleHeight     =   127
  224.          ScaleMode       =   3  'Pixel
  225.          ScaleWidth      =   135
  226.          TabIndex        =   7
  227.          Top             =   240
  228.          Width           =   2055
  229.       End
  230.       Begin VB.Label Label4 
  231.          Alignment       =   2  'Center
  232.          AutoSize        =   -1  'True
  233.          BackStyle       =   0  'Transparent
  234.          Caption         =   "You can move image by draging the mouse"
  235.          Height          =   195
  236.          Index           =   3
  237.          Left            =   1305
  238.          TabIndex        =   21
  239.          Top             =   0
  240.          Width           =   3060
  241.       End
  242.    End
  243.    Begin VB.PictureBox PicBk 
  244.       Height          =   5055
  245.       Index           =   2
  246.       Left            =   120
  247.       ScaleHeight     =   4995
  248.       ScaleWidth      =   5100
  249.       TabIndex        =   2
  250.       Top             =   6360
  251.       Width           =   5160
  252.       Begin VB.PictureBox Pic 
  253.          Appearance      =   0  'Flat
  254.          AutoSize        =   -1  'True
  255.          BackColor       =   &H80000005&
  256.          ForeColor       =   &H80000008&
  257.          Height          =   1935
  258.          Index           =   2
  259.          Left            =   1560
  260.          MouseIcon       =   "FrmMain.frx":0614
  261.          MousePointer    =   99  'Custom
  262.          ScaleHeight     =   127
  263.          ScaleMode       =   3  'Pixel
  264.          ScaleWidth      =   135
  265.          TabIndex        =   6
  266.          Top             =   240
  267.          Width           =   2055
  268.       End
  269.       Begin VB.Label Label4 
  270.          Alignment       =   2  'Center
  271.          AutoSize        =   -1  'True
  272.          BackStyle       =   0  'Transparent
  273.          Caption         =   "You can move image by draging the mouse"
  274.          Height          =   195
  275.          Index           =   2
  276.          Left            =   945
  277.          TabIndex        =   20
  278.          Top             =   0
  279.          Width           =   3060
  280.       End
  281.    End
  282.    Begin VB.PictureBox PicBk 
  283.       Height          =   5055
  284.       Index           =   1
  285.       Left            =   5760
  286.       ScaleHeight     =   4995
  287.       ScaleWidth      =   5100
  288.       TabIndex        =   1
  289.       Top             =   120
  290.       Width           =   5160
  291.       Begin VB.PictureBox Pic 
  292.          Appearance      =   0  'Flat
  293.          AutoRedraw      =   -1  'True
  294.          AutoSize        =   -1  'True
  295.          BackColor       =   &H80000005&
  296.          ForeColor       =   &H80000008&
  297.          Height          =   3945
  298.          Index           =   1
  299.          Left            =   2040
  300.          MouseIcon       =   "FrmMain.frx":091E
  301.          MousePointer    =   99  'Custom
  302.          Picture         =   "FrmMain.frx":0C28
  303.          ScaleHeight     =   261
  304.          ScaleMode       =   3  'Pixel
  305.          ScaleWidth      =   172
  306.          TabIndex        =   5
  307.          Top             =   480
  308.          Width           =   2610
  309.       End
  310.       Begin VB.Label Label4 
  311.          Alignment       =   2  'Center
  312.          AutoSize        =   -1  'True
  313.          BackStyle       =   0  'Transparent
  314.          Caption         =   "You can move image by draging the mouse"
  315.          Height          =   195
  316.          Index           =   1
  317.          Left            =   1785
  318.          TabIndex        =   19
  319.          Top             =   0
  320.          Width           =   3060
  321.       End
  322.    End
  323.    Begin MSComDlg.CommonDialog dlgPicture 
  324.       Left            =   -120
  325.       Top             =   5760
  326.       _ExtentX        =   847
  327.       _ExtentY        =   847
  328.       _Version        =   393216
  329.    End
  330.    Begin VB.PictureBox PicBk 
  331.       Height          =   5055
  332.       Index           =   0
  333.       Left            =   120
  334.       ScaleHeight     =   4995
  335.       ScaleWidth      =   5100
  336.       TabIndex        =   0
  337.       Top             =   120
  338.       Width           =   5160
  339.       Begin VB.PictureBox Pic 
  340.          Appearance      =   0  'Flat
  341.          AutoRedraw      =   -1  'True
  342.          AutoSize        =   -1  'True
  343.          BackColor       =   &H80000005&
  344.          ForeColor       =   &H80000008&
  345.          Height          =   3945
  346.          Index           =   0
  347.          Left            =   1080
  348.          MouseIcon       =   "FrmMain.frx":51D3
  349.          MousePointer    =   99  'Custom
  350.          Picture         =   "FrmMain.frx":54DD
  351.          ScaleHeight     =   261
  352.          ScaleMode       =   3  'Pixel
  353.          ScaleWidth      =   172
  354.          TabIndex        =   4
  355.          Top             =   480
  356.          Width           =   2610
  357.       End
  358.       Begin VB.Label Label4 
  359.          Alignment       =   2  'Center
  360.          AutoSize        =   -1  'True
  361.          BackStyle       =   0  'Transparent
  362.          Caption         =   "You can move image by draging the mouse"
  363.          Height          =   195
  364.          Index           =   0
  365.          Left            =   705
  366.          TabIndex        =   18
  367.          Top             =   0
  368.          Width           =   3060
  369.       End
  370.    End
  371. End
  372. Attribute VB_Name = "FrmMain"
  373. Attribute VB_GlobalNameSpace = False
  374. Attribute VB_Creatable = False
  375. Attribute VB_PredeclaredId = True
  376. Attribute VB_Exposed = False
  377. 'Code by Cm.Shafi
  378. Option Explicit
  379. Private Declare Function SetPixel Lib "gdi32" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long, ByVal crColor As Long) As Long
  380. Private Declare Function GetPixel Lib "gdi32" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long) As Long
  381. 'Private Declare Function StretchBlt Lib "gdi32" (ByVal hDC 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 nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
  382. Dim dXM(3) As Long, DYM(3) As Long
  383. Dim isStart As Boolean
  384. Private Sub CmdAction_Click()
  385.  Dim Xp As Long, Yp As Long, Xd As Long, Yd As Long, i As Long, j As Long
  386.     Dim P1, P2
  387.     Dim a1, a2
  388.     Dim G As Long, M As Long
  389.     Pic(0).ScaleMode = vbPixels         'to Pixel mode
  390.     Pic(1).ScaleMode = vbPixels
  391.  
  392.     For i = 2 To 3
  393.         Set Pic(i).Picture = LoadPicture() 'clear Previous result
  394.         Pic(i).Cls
  395.     Next
  396.     Label1.Caption = "Match:" & " %"
  397.     Label2.Caption = "Not Match:" & " %"
  398.     If Pic(0).Height <= Pic(1).Height Then
  399.         Pic(2).Height = Pic(0).Height
  400.         Pic(3).Height = Pic(1).Height
  401.     Else
  402.         Pic(2).Height = Pic(1).Height
  403.         Pic(3).Height = Pic(0).Height
  404.     End If
  405.     If Pic(0).Width <= Pic(1).Width Then
  406.         Pic(2).Width = Pic(0).Width
  407.         Pic(3).Width = Pic(1).Width
  408.     Else
  409.         Pic(2).Width = Pic(1).Width
  410.         Pic(3).Width = Pic(0).Width
  411.     End If
  412.      For i = 0 To 3
  413.         Pic(i).Move (PicBk(i).Width - Pic(i).Width) / 2, (PicBk(i).Height - Pic(i).Height) / 2 ' set default position
  414.     Next
  415.     DoEvents
  416.     Xp = Pic(0).ScaleWidth
  417.     Yp = Pic(0).ScaleHeight
  418.      a1 = (Xp) * (Yp)
  419.     Pic(2).Cls
  420.      Pic(3).Cls
  421.     For i = 0 To Xp - 1
  422.         For j = 0 To Yp - 1
  423.             P1 = GetPixel(Pic(0).hDC, i, j)     'Get colour from images pixel by pixel
  424.             P2 = GetPixel(Pic(1).hDC, i, j)
  425.             If P1 = P2 Then
  426.                 G = G + 1
  427.                 a2 = SetPixel(Pic(2).hDC, i, j, P2) 'Set pixel to result's image
  428.                 Else
  429.                 If (P1 < (P2 + 1000000) And P1 > (P2 - 1000000)) And Check1.Value = 0 Then
  430.                 G = G + 1
  431.                 a2 = SetPixel(Pic(2).hDC, i, j, P2)
  432.                 Else
  433.                 a2 = SetPixel(Pic(3).hDC, i, j, P2)
  434.                 M = M + 1
  435.                 End If
  436.             End If
  437. '            Label1.Caption = "Match:" & Round((G * 100) / a1, 4) & " %"
  438. '            Label2.Caption = "Not Match:" & Round((M * 100) / a1, 4) & " %"
  439.         Next
  440.         Label1.Caption = "Match:" & Round((G * 100) / a1, 4) & " %"
  441.         Label2.Caption = "Not Match:" & Round((M * 100) / a1, 4) & " %"
  442.     Next
  443. '    Label1.Caption = "Match:" & Round((G * 100) / a1, 4) & " %"
  444. '    Label2.Caption = "Not Match:" & Round((M * 100) / a1, 4) & " %"
  445.     
  446. End Sub
  447.  
  448.  
  449. Private Sub CmdBrowse1_Click()
  450. Dim sFile As String
  451. Dim Bcolor As ColorConstants
  452.     dlgPicture.Flags = _
  453.         cdlOFNFileMustExist Or _
  454.         cdlOFNHideReadOnly Or _
  455.         cdlOFNExplorer
  456.     dlgPicture.CancelError = True
  457.     dlgPicture.Filter = "Graphics Files|*.bmp;*.ico;*.jpg;*.gif"
  458.  
  459.     On Error Resume Next
  460.     dlgPicture.ShowOpen
  461.     If Err.Number = cdlCancel Then
  462.         Exit Sub
  463.     ElseIf Err.Number <> 0 Then
  464.         MsgBox "Error " & Format$(Err.Number) & _
  465.             " selecting file." & vbCrLf & Err.Description
  466.         Exit Sub
  467.     End If
  468.    sFile = dlgPicture.FileName
  469. Set Pic(0).Picture = LoadPicture(sFile)
  470.  
  471. End Sub
  472.  
  473. Private Sub CmdBrowse2_Click()
  474. Dim sFile As String
  475. Dim Bcolor As ColorConstants
  476.     dlgPicture.Flags = _
  477.         cdlOFNFileMustExist Or _
  478.         cdlOFNHideReadOnly Or _
  479.         cdlOFNExplorer
  480.     dlgPicture.CancelError = True
  481.     dlgPicture.Filter = "Graphics Files|*.bmp;*.ico;*.jpg;*.gif"
  482.  
  483.     On Error Resume Next
  484.     dlgPicture.ShowOpen
  485.     If Err.Number = cdlCancel Then
  486.         Exit Sub
  487.     ElseIf Err.Number <> 0 Then
  488.         MsgBox "Error " & Format$(Err.Number) & _
  489.             " selecting file." & vbCrLf & Err.Description
  490.         Exit Sub
  491.     End If
  492.    sFile = dlgPicture.FileName
  493. Set Pic(1).Picture = LoadPicture(sFile)
  494.  
  495. End Sub
  496.  
  497. Private Sub Cmdclear_Click()
  498.     Dim i As Integer
  499.     For i = 0 To 3
  500.         Set Pic(i).Picture = LoadPicture()
  501.         Pic(i).Cls
  502.     Next
  503.     Label1.Caption = "Match:" & " %"
  504.     Label2.Caption = "Not Match:" & " %"
  505.     
  506. End Sub
  507.  
  508. Private Sub CmdRefresh_Click()
  509.     Dim i As Integer
  510.     For i = 2 To 3
  511.         Set Pic(i).Picture = LoadPicture()
  512.         Pic(i).Cls
  513.     Next
  514.     Label1.Caption = "Match:" & " %"
  515.     Label2.Caption = "Not Match:" & " %"
  516.  
  517. End Sub
  518.  
  519. Private Sub Form_Load()
  520. Dim i As Integer
  521.     Me.Move 0, 0, Screen.Width, Screen.Height
  522.     
  523.     PicBk(0).Move 0, 0, (Me.Width / 2) - 60, (Me.Height - 1500) / 2
  524.     PicBk(1).Move PicBk(0).Width + 60, 0, (Me.Width / 2) - 60, (Me.Height - 1500) / 2
  525.     PicBk(2).Move 0, PicBk(0).Height + 1000, (Me.Width / 2) - 60, (Me.Height - 1500) / 2
  526.     PicBk(3).Move PicBk(0).Width + 60, PicBk(0).Height + 1000, (Me.Width / 2) - 60, (Me.Height - 1500) / 2
  527.     Picture1.Move 0, PicBk(0).Height, Me.Width, 1000
  528.     CmdBrowse1.Left = (PicBk(0).Width - CmdBrowse1.Width) / 2
  529.     CmdBrowse2.Left = PicBk(0).Width + 60 + (PicBk(1).Width - CmdBrowse2.Width) / 2
  530.     Label1.Left = (PicBk(0).Width - Label1.Width) / 2
  531.     Label2.Left = PicBk(0).Width + 60 + (PicBk(1).Width - Label2.Width) / 2
  532.     CmdAction.Left = (Me.Width - CmdAction.Width) / 2
  533.     CmdRefresh.Left = (Me.Width - CmdRefresh.Width) - 260
  534.     Check1.Left = (Me.Width - Check1.Width) / 2
  535.     Shape1.Left = 0
  536.     Shape1.Width = Me.Width
  537.     For i = 0 To 3
  538.         Pic(i).Move (PicBk(i).Width - Pic(i).Width) / 2, (PicBk(i).Height - Pic(i).Height) / 2
  539.         Label4(i).Left = (PicBk(i).Width - Label4(i).Width) / 2
  540.     Next
  541.     
  542. End Sub
  543.  
  544.  
  545.  
  546. Private Sub Pic_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
  547.     isStart = True
  548.     dXM(Index) = X
  549.     DYM(Index) = Y
  550. End Sub
  551.  
  552. Private Sub Pic_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
  553.     If isStart Then
  554.         Pic(Index).Left = Pic(Index).Left + (X - dXM(Index))
  555.         Pic(Index).Top = Pic(Index).Top + (Y - DYM(Index))
  556.         Me.Refresh
  557.     End If
  558. End Sub
  559.  
  560. Private Sub Pic_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
  561.     isStart = False
  562. End Sub
  563.