Author : Ward Jaradat
Date Submitted : 3/6/2006
Category : Graphics
Compatibility : VB 6
This code has been accessed 5215 times.
Task : Code that scans pixels of two given images to indicate whether they were identical or not
Declarations
Code
'*********************************************
' This code was designed by Ward Jaradat
'
' E-mail & MSN Messanger Handler:
' wardgalactica@bluebottle.com
'
' Website:
' http://wardgalactica.blogspot.com
'*********************************************
'---------------------------------------------
' This code's purpose is to scan two given
' images' pixels to find out if they were
' identical or not!
'---------------------------------------------
Option Explicit
Public Enum myColor ' RGB Color Values
R As Long
G As Long
B As Long
End Enum
Public Enum myResults
T As Long ' for total pixels
I As Long ' for identical pixels
N As Long ' for non-identical pixels
P As Long ' for how much percent the two images are identical
End Enum
Public Result As myResults
' Information:
' this code works on 16bpp format for images, actually i would like
' to make some points clear regarding this issue:
'
' ----------------------------------------------------------------------
'
' * RGB 5:5:5 is the default format so its actually 15bpp where the
' top bit is alwayz empty or not used!
'
' * In this format 16bpp, each of the Red, Green, & Blue
' color components is presented by a 5 bit number giving
' 32 different levels of each and 32786 possible different
' colors in total; which means that the true 16bpp would be
' RGB 5:6:5 where there are 65536 possible colors!
'
' * There is no palette used to define the colors for the 16bpp images
' however the Red, Green, & Blue values in the pixel are used to
' define the colors directly!
'
' ----------------------------------------------------------------------
' However if u like to know more about RGB formats u could do some search
' on google or something... :D
'
Public Function ScanPixels(myPic1 As PictureBox, myPic2 As PictureBox)
Dim PointX As Long
Dim PointY As Long
Dim X As Long
Dim Y As Long
Dim ColorX As myColor
Dim ColorY As myColor
' Note that the resolution of myPic1 & myPic2 should be identical
If Not (myPic1.Height = myPic2.Height) Then
Exit Function
ElseIf Not (myPic1.Width = myPic2.Width) Then
Exit Function
End If
Do Until (Y > myPic1.Height)
PointX = Picture1.Point(X, Y)
PointY = Picture2.Point(X, Y)
myRGB PointX, ColorX.R, ColorX.G, ColorX.B
myRGB PointY, ColorY.R, ColorY.G, ColorY.B
If (ColorX.R = ColorY.R) And (ColorX.G = ColorY.G) And (ColorX.B = ColorY.B) Then
Result.I = Result.I + 1
Else
Result.N = Result.N + 1
End If
Result.T = Result.T + 1
X = X + 15 ' why 15? check the information above!
If X > myPic1.Width Then
X = 0
Y = Y + 15
End If
Loop
Result.P = (100 - ((Result.N / Result.T) * 100))
End Function
Public Function myRGB(ByVal myPoint As Long, Red As Long, Green As Long, Blue As Long)
G = Int(ColorValue / 65536)
B = Int((ColorValue - (65536 * G)) / 256)
R = ColorValue - (65536 * G + 256 * B)
' However, just if u wanna know how to get RGB values in the reverse order
' of bytes u could return the value of the following code:
'
' CLng(blue + (green * 256) + (red * 65536)
'
' I did truly find that useful in making other functions regarding RGB :D
End Function