Hi all

I need to compare to jpeg images and display the differences. This is what i have written but it does not work.



Private Declare Function GetPixel Lib "GDI32" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function SetPixel Lib "GDI32" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long

Public Function Min(ByVal d1 As Integer, ByVal d2 As Integer) As Integer
Min = d1
If d2 < d1 Then Min = d2
End Function

Private Sub CommandButtonGenerate_Click()

' Load the images.

Dim RefPath As String
Dim StudPath As String

StudPath = CommonDialogDrawStudent.FileName
RefPath = CommonDialogDraw.FileName

ImageStud.Picture = LoadPicture(StudPath)
ImageRef.Picture = LoadPicture(RefPath)

' Make a difference image.
Dim wid As Integer
Dim hgt As Integer

wid = Min(ImageStud.Picture.Width, ImageRef.Picture.Width)
hgt = Min(ImageStud.Picture.Height, ImageRef.Picture.Height)

Dim x As Integer
Dim y As Integer

Dim ColourStud As Long
Dim ColourRef As Long
Dim Resultdiff As Long 'this is where the error comes in, but i couldnt figure it out

ImageDiff.Picture.Width = wid
ImageDiff.Picture.Height = hgt

ColourStud = ImageStud.Picture
ColourRef = ImageRef.Picture

Resultdiff = ImageDiff.Picture

For x = 0 To wid - 1
For y = 0 To hgt - 1

If GetPixel(ColourStud, x, y) = GetPixel(ColourRef, x, y) Then
SetPixel Resultdiff, x, y, &H0
Else
SetPixel Resultdiff, x, y, &HFF0000

End If
Next y
Next x

End Sub