Help with colors

Hello all,

I am reading the colors of an image that consists of grays, reds with black grid lines. I am using the grid as a “box” to size an object on a canvas.

My challenge comes in where not all blacks are equal. I was using this code, but it did not work universally:

If surf.Pixel( nx, ny) <> OrgColor Then
If surf.Pixel( nx, ny) = &c00000000 OR surf.Pixel(nx, ny) = &c03030300 Then

I think what I really need to do is something like this where a range of color values are acceptable:

if surf.Pixel( nx, ny) >= &c00000000 AND surf.Pixel( nx, ny) <= &c03030300 Then

However this fails in compile with the complaint" Undefined operator. Type color does not define “>=” with type color.

I also tried with this:
Dim col As Color = surf.Pixel( nx, ny)
if Col >= &c00000000 AND Col <= &c03030300 Then

but, it too fails with the same message.

Can anyone tell me how to do this?

Thank you!
Tim

I’m sure others will have better ideas than this, but you could use color.ToString.

try

dim tst as color = surf.Pixel( nx, ny) 
if   (tst.red + tst.green + tst.blue )  < 80  then   //arbitrary value.. experiment with the threshold?
//its dark
end if

You could do this with a method like this:

Function isBetween(compareColor as Color, firstColor as Color, secondColor as Color) as Boolean
    If compareColor.Red < min(firstColor.Red, secondColor.Red) or compareColor.Red > max(firstColor.Red, secondColor.Red) then
        Return False
    End If

     If compareColor.Green < min(firstColor.Green, secondColor.Green) or compareColor.Green > max(firstColor.Green, secondColor.Green) then
        Return False
    End If

    If compareColor.Blue < min(firstColor.Blue, secondColor.Blue) or compareColor.Blue > max(firstColor.Blue, secondColor.Blue) then
        Return False
    End If

    Return True
End Function

Thank you all!

Greg, your function works best. Norman had a suggestion too, and that helped, but yours really did a great job.

Also, I changed the location (nx, ny) where we inspect the color of the pixel. This helped cure the problem too.

Thanks again everyone!
Tim