View Single Post
  #5 (permalink)  
Old 06-09-2009, 4:02 PM
sonia.sardana sonia.sardana is offline
VB.NET Forum Enthusiast
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Jan 2009
Age: 24
Posts: 34
Reputation: 16
sonia.sardana is on a distinguished programming path ahead
Default

Thx very much but ...Conversion process didnt work 100 % Corectly..

Tested & complete Code-
FIRST METHOD
Code:
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim img1 As Bitmap = Image.FromFile("D:\Documents and Settings\Sonia\Desktop\sonia1.bmp")
        Dim img2 As Bitmap = Image.FromFile("D:\Documents and Settings\Sonia\Desktop\sonia2.bmp")
        Dim a As Boolean
        a = doImagesMatch(img1, img2)
    End Sub

    Public Function doImagesMatch(ByVal bmp1 As Bitmap, ByVal bmp2 As Bitmap) As Boolean
        Dim converter As ImageConverter = New ImageConverter()
        Dim i As Integer
        Dim imgBytes1(0) As Byte
        Dim imgBytes2(0) As Byte
        imgBytes1 = CType(converter.ConvertTo(bmp1, imgBytes1.GetType()), Byte())

        imgBytes2 = CType(converter.ConvertTo(bmp2, imgBytes1.GetType()), Byte())
        Dim sha As SHA256Managed = New SHA256Managed()

        Dim imgHash1 As Byte() = sha.ComputeHash(imgBytes1)

        Dim imgHash2 As Byte() = sha.ComputeHash(imgBytes2)
        For i = 0 To imgHash1.Length - 1 And imgHash2.Length - 1
            If ((imgHash1(i) <> imgHash2(i))) Then
                doImagesMatch = False
            Else
                doImagesMatch = True
            End If
        Next
    End Function
SECOND METHOD
Code:
Dim img1 As Bitmap = New Bitmap("D:\\Documents and Settings\\Sonia\\Desktop\\sonia1.bmp")
Dim img2 As Bitmap = New Bitmap("D:\\Documents and Settings\\Sonia\\Desktop\\sonia2.bmp")
Dim a As Boolean
a= doImagesMatch(img1,img2)
End Sub

Public Function doImagesMatch(ByVal bmp1 As Bitmap, ByVal bmp2 As Bitmap) As Boolean
Try

'each image to a byte array

Dim converter As ImageConverter = New ImageConverter()
'create 2 byte arrays, one for each image
Dim imgBytes1() As Byte = New Byte(1) {}
Dim imgBytes2() As Byte = New Byte(1) {}

'convert images to byte array
imgBytes1 = CType(converter.ConvertTo(bmp1, imgBytes2.GetType()), Byte())
imgBytes2 = CType(converter.ConvertTo(bmp2, imgBytes1.GetType()), Byte())

'now compute a hash for each image from the byte arrays

Dim sha As SHA256Managed = New SHA256Managed()
Dim imgHash1() As Byte = sha.ComputeHash(imgBytes1)
Dim imgHash2() As Byte = sha.ComputeHash(imgBytes2)

'now let's compare the hashes

Dim i As Integer
For i = 0 To imgHash1.Length And i < imgHash2.Length- 1 Step i + 1
If Not (imgHash1(i) = imgHash2(i)) Then
Return False
End If
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
Return False
End Try
Return True
End Function
Hey i want to ask that frnds Suppose if i have mine full image..& suppose i edit it with paint & cut it half..& then compare full image & half image...then function returns fals....I want to just ask dat can we do i Vb.net..to compare two images one full & one half...& still we get true.....
Reply With Quote