Home All Groups Group Topic Archive Search About
Author
2 Mar 2006 5:33 PM
fripper
I have a simple VB 2005 app that has a bitmap image and at one point I want
to look at a particular pixel and see if it has a color value equal to the
value of a color variable, c.  For example:

dim c as color

c = color.red

If bitmap(x,y) = c then
       .
       .
       .

For reaons that I don't understand the equality is not recognized even
though I am in debug mode and I can see that the value of c and bitmap(x,y)
are identical.  Is there some secret to comparing color values in VB 2005?

Thanks.

Author
2 Mar 2006 6:21 PM
Peter Macej
Use Color.ToArgb method:

If color1.ToArgb = color2.ToArgb Then


--
Peter Macej
Helixoft - http://www.vbdocman.com
VBdocman - Automatic generator of technical documentation for VB, VB
..NET and ASP .NET code
Author
2 Mar 2006 7:17 PM
fripper
That did it ... thanks a lot.  I don't understand why

       If color1 = color2 then ...

doesn't work.






Show quoteHide quote
"Peter Macej" <pe***@vbdocman.com> wrote in message
news:%23%23XCsYiPGHA.668@TK2MSFTNGP11.phx.gbl...
> Use Color.ToArgb method:
>
> If color1.ToArgb = color2.ToArgb Then
>
>
> --
> Peter Macej
> Helixoft - http://www.vbdocman.com
> VBdocman - Automatic generator of technical documentation for VB, VB .NET
> and ASP .NET code
Author
2 Mar 2006 8:10 PM
Peter Macej
> That did it ... thanks a lot.  I don't understand why
>
>        If color1 = color2 then ...
>
> doesn't work.

Color is an object - reference type. You cannot simply compare two
objects by "=" because objects may be very complex with many properties
which themselves may be complex nested data types.

String is one exception, it's object and you can compare it with "=".
Normally you can only compare primitive types like Integer or Boolean.
Color.ToArgb returns Integer and that's why you can compare it.


--
Peter Macej
Helixoft - http://www.vbdocman.com
VBdocman - Automatic generator of technical documentation for VB, VB
..NET and ASP .NET code
Author
2 Mar 2006 11:19 PM
Herfried K. Wagner [MVP]
"Peter Macej" <pe***@vbdocman.com> schrieb:
>> That did it ... thanks a lot.  I don't understand why
>>
>>        If color1 = color2 then ...
>>
>> doesn't work.
>
> Color is an object - reference type.

'Color' is a value type (structure).

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
2 Mar 2006 8:00 PM
Armin Zingler
Show quote Hide quote
"fripper" <yo***@indiana.edu> schrieb
>
> I have a simple VB 2005 app that has a bitmap image and at one point
> I want to look at a particular pixel and see if it has a color value
> equal to the value of a color variable, c.  For example:
>
> dim c as color
>
> c = color.red
>
> If bitmap(x,y) = c then
>       .
>       .
>       .
>
> For reaons that I don't understand the equality is not recognized
> even though I am in debug mode and I can see that the value of c and
> bitmap(x,y) are identical.  Is there some secret to comparing color
> values in VB 2005?

In addition to Peter's answer:
There is no secret. You can compare strings and numeric values, but not
complex objects. Which properties do you want to compare? The R value? G
value? B value?


Armin
Author
2 Mar 2006 8:35 PM
Armin Zingler
"Armin Zingler" <az.nospam@freenet.de> schrieb
> In addition to Peter's answer:
> There is no secret. You can compare strings and numeric values, but
> not complex objects. Which properties do you want to compare? The R
> value? G value? B value?

I was talking about the Color type. In your own classes, you can define your
own comparison operators. Not available in VB 2003.


Armin
Author
3 Mar 2006 1:11 PM
Phill W.
"fripper" <yo***@indiana.edu> wrote in message
news:u6p329hPGHA.3576@TK2MSFTNGP15.phx.gbl...
>
> Is there some secret to comparing color values in VB 2005?

Unless it's changed from VB 2003 ...

Dim c1 as Color = Color.Back
Dim c2 as Color = Color.Green

If c1.Equals( c2 ) Then
    ...

HTH,
    Phill  W.
Author
3 Mar 2006 2:09 PM
Larry Lard
Phill  W. wrote:
> "fripper" <yo***@indiana.edu> wrote in message
> news:u6p329hPGHA.3576@TK2MSFTNGP15.phx.gbl...
> >
> > Is there some secret to comparing color values in VB 2005?
>
> Unless it's changed from VB 2003 ...
>
> Dim c1 as Color = Color.Back
> Dim c2 as Color = Color.Green
>
> If c1.Equals( c2 ) Then

It is unfortunate that while this looks like the right thing to do, it
isn't. From the docs for Color.Equals (my emphasis):

>>
This structure only does comparisons with other Color structures. To
compare colors based solely on their ARGB values, you should do the
following:

if ( color1.ToArgb() == color2.ToArgb()) ...

This is because the .Equals and == operators determine equivalency
using more than just the ARGB value of the colors. ****For example,
Color.Black and Color.FromArgb(0,0,0) are not considered equal since
Color.Black is a named color and Color.FromArgb(0,0,0) is not.****
>>

I'm not a philosopher, so I can't make an _educated_ comment on the
logic that leads Color.Black and RGB 0,0,0 to be regarded as 'not
equal' ...

--
Larry Lard
Replies to group please
Author
4 Mar 2006 10:21 PM
fripper
Thanks for the clear and helpful comments.



Show quoteHide quote
"Larry Lard" <larryl***@hotmail.com> wrote in message
news:1141394987.597772.183280@i39g2000cwa.googlegroups.com...
>
> Phill  W. wrote:
>> "fripper" <yo***@indiana.edu> wrote in message
>> news:u6p329hPGHA.3576@TK2MSFTNGP15.phx.gbl...
>> >
>> > Is there some secret to comparing color values in VB 2005?
>>
>> Unless it's changed from VB 2003 ...
>>
>> Dim c1 as Color = Color.Back
>> Dim c2 as Color = Color.Green
>>
>> If c1.Equals( c2 ) Then
>
> It is unfortunate that while this looks like the right thing to do, it
> isn't. From the docs for Color.Equals (my emphasis):
>
>>>
> This structure only does comparisons with other Color structures. To
> compare colors based solely on their ARGB values, you should do the
> following:
>
> if ( color1.ToArgb() == color2.ToArgb()) ...
>
> This is because the .Equals and == operators determine equivalency
> using more than just the ARGB value of the colors. ****For example,
> Color.Black and Color.FromArgb(0,0,0) are not considered equal since
> Color.Black is a named color and Color.FromArgb(0,0,0) is not.****
>>>
>
> I'm not a philosopher, so I can't make an _educated_ comment on the
> logic that leads Color.Black and RGB 0,0,0 to be regarded as 'not
> equal' ...
>
> --
> Larry Lard
> Replies to group please
>