OK Marc, I’m going to try Andrew’s suggestion first (sinse it’s simpler) and if using the ‘is not’ operator doesn’t work I’ll give your idea a shot.
Thank for the replies everyone, I’ll let you know how it works out.
OK Marc, I’m going to try Andrew’s suggestion first (sinse it’s simpler) and if using the ‘is not’ operator doesn’t work I’ll give your idea a shot.
Thank for the replies everyone, I’ll let you know how it works out.
The syntax would be If Not (Ref1 Is Ref2) Then
rather than If Ref1 Is Not Ref2
To answer your question as asked, here is a method to determine if two pictures are the same (the way a human would consider the “same”):
Function SamePictures(p1 As Picture, p2 As Picture) As Boolean
select case true
case p1 is p2
return true
case p1 is nil, p2 is nil
return false
case p1.Width <> p2.Width, p1.Height <> p2.Height, p1.Depth <> p2.Depth
return false
end select
// If we get here, they are both pictures of the same size
dim r1 as RGBSurface = p1.RGBSurface
dim r2 as RGBSurface = p2.RGBSurface
dim width as integer = p1.Width - 1
dim height as integer = p1.Height - 1
for y as integer = 0 to height
for x as integer = 0 to width
dim px1 as Color = r1.Pixel( x, y )
dim px2 as Color = r2.Pixel( x, y )
if px1.Red <> px2.Red or px1.Green <> px2.Green or px1.Blue <> px2.Blue then
return false
end if
next x
next y
// If we get here, they are the same
return true
End Function
Andrew, IT WORKED!!! THANK YOU!
You know, I did a lot of research in help reference before turning to this forum for help. No where did I find the syntax you provided.
Kem, thank you for effort in answering my question but thank goodness I don’t have to go that route. I will however store your snippet for possible future use.
The advantage of using that code is that it first checks to see if they are the same object anyway. Only if they are not the same object, and only if they are the same width, height, and depth, does it actually compare the actual images.
This is a much faster version. For a 4000x5000 image, it takes about 0.5 seconds here:
Function SamePictures(p1 As Picture, p2 As Picture) As Boolean
select case true
case p1 is p2
return true
case p1 is nil, p2 is nil
return false
case p1.Width <> p2.Width, p1.Height <> p2.Height, p1.Depth <> p2.Depth
return false
end select
// If we get here, they are both pictures of the same size
return StrComp( p1.GetData( Picture.FormatTIFF ), p2.GetData( Picture.FormatTIFF ), 0 ) = 0
End Function
[quote=23757:@Peter Gattignolo]Andrew, IT WORKED!!! THANK YOU!
You know, I did a lot of research in help reference before turning to this forum for help. No where did I find the syntax you provided.
[/quote]
The syntax is not explicitly mentioned in the docs, but just remember that Is
is a comparison operator just like =
, <
, >
, <=
, >=
, or <>
and so you must use operator syntax (i.e. [LeftVariable][Operator][RightVariable]
).
The parentheses I used override the normal operator precedence (in which Not
is evaluated before Is
), otherwise the compiler would have interpreted it as If (Not Ref1) Is Ref2
which isn’t meaningful and raises a compiler error since the logical Not operator only works with booleans and Is
only works with objects.
By writing (Ref1 Is Ref2)
the parentheses allow the subexpression to be evaluated and treated as a boolean value in the rest of the expression.
While I do advocate the us of “is”, I would like to point out to the newer users following this thread that the normal comparison operators, “=” and “<>” would have worked as well. You can get into trouble using “=” and “<>” if you have Operator_Compare implemented, which is why “is” is often preferable, but they do work in this situation.
But wasn’t that the purpose of this conversation in the first place – that <> wasn’t working in this context?
No, it was a simple logic error in the original post.