|
-
Jul 20th, 2007, 07:32 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] [2005] Load & Comparing Graphic Files
Two questions:
1) How do you load a graphic file into a variable in VB? I assumed you would use an Image variable, by how do you load it? I want to load jpg files.
2) How do you compare two graphic files? If I can load the files into Image variables I can use either .equals or .gethashcode methods (and then compare the hashcodes). Is this the best way or is there another?
-
Jul 20th, 2007, 07:53 AM
#2
Re: [2005] Load & Comparing Graphic Files
1. Image.FromFile
2. Comparing Image objects and comparing images are completely different. The Image.Equals method simply tells you whether two variables refer to the same Image object. If you've called Image.FromFile twice then Equals must return False, even if you called FromFile twice on the same file. If you want to compare image files then you will have to do so by comparing each pixel of the two images. Of course, that's assuming that they're both the same dimensions, which they must be to be the same.
-
Jul 20th, 2007, 08:16 AM
#3
Thread Starter
Fanatic Member
Re: [2005] Load & Comparing Graphic Files
Image.fromfile seems to work (atleast no errors). I tried comparing hashcodes, and that also does not work, even loading the same file (as you indicated for .equals). So much for the easy way of doing it.
Can you give me any pointers as to how to do the pixel by pixel comparison? I could not find where to get the pixel data. BTW, does this approach work for both jpg and bmp file formats?
-
Jul 20th, 2007, 10:42 AM
#4
Thread Starter
Fanatic Member
Re: [2005] Load & Comparing Graphic Files
I figured it out. The loaded images had to be loaded as Bitmaps.
vb Code:
Dim img, imgFile As Bitmap
img = Image.FromFile(strTemp.Trim & ".jpg", True)
Then I wrote a function that compared the two images.
vb Code:
Function CompareImages(ByVal imgA As Bitmap, ByVal imgB As Bitmap) As Boolean
Dim WidthA, WidthB, HeightA, HeightB As Integer
Dim i, j As Integer
Dim flag As Boolean
widthA = imgA.Width
widthB = imgB.Width
heightA = imgA.Height
HeightB = imgB.Height
flag = True
If WidthA = WidthB AndAlso HeightA = HeightB Then
For i = 0 To WidthA - 1
For j = 0 To HeightB - 1
If imgA.GetPixel(i, j) <> imgB.GetPixel(i, j) Then
flag = False
i = WidthA
j = HeightA
End If
Next
Next
Else
flag = False
End If
CompareImages = flag
End Function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|