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 9 5433
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
That did it ... thanks a lot. I don't understand why
If color1 = color2 then ...
doesn't work.
"Peter Macej" <pe***@vbdocman.com> wrote in message
news:%2*****************@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
> 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
"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
"Armin Zingler" <az*******@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
"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/>
"fripper" <yo***@indiana.edu> wrote in message
news:u6**************@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.
Phill W. wrote: "fripper" <yo***@indiana.edu> wrote in message news:u6**************@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
Thanks for the clear and helpful comments.
"Larry Lard" <la*******@hotmail.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com... Phill W. wrote: "fripper" <yo***@indiana.edu> wrote in message news:u6**************@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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Jeff Thies |
last post by:
I need to check if two hashes are identical.
My thoughts are something like this:
function compareHash(hash1,hash2){
if(hash1.length != hash2.length){return false}
for(var key in hash1){...
|
by: Robert Dell |
last post by:
I have a problem comparing strings in an order form i'm writing. I want
to give a running total at the bottom of the page and it appears to be
working except it doesn't compare correctly (it...
|
by: Danny Lesandrini |
last post by:
I'm using an Access database to drive a web site and the
colors of various table backgrounds are stored in Access.
I want users of the Access database to be able to select
colors for the site, but...
|
by: Typpo |
last post by:
Hi all,
I'm trying to compare a color returned by a Bitmap's GetPixel method to
a normal static color of the Color class. My problem: after setting a
pixel to a certain color, the color...
|
by: Paul Smith |
last post by:
I have a button on my web page the backcolor of which I want to change:
btnSample.backcolor = ????????
I want the color to be Gainsboro
However I enter Gainsboro or color.Gainsboro I have...
|
by: Dennis |
last post by:
I have a public variable in a class of type color declared as follows:
public mycolor as color = color.Empty
I want to check to see if the user has specified a color like;
if mycolor =...
|
by: dtschoepe |
last post by:
Greetings.
I am working on an assignment and can't seem to get the right concept
for something I'm attempting to do with enum data types.
I have defined the following in my code:
enum color...
|
by: Zytan |
last post by:
I wanted to do something simple like checking my own Color variable
against Color.Black, and == returned false, even though their RGB
values were all 0! Of course, there's the A (alpha) value, but...
|
by: MarkoKlacar |
last post by:
Does anyone know a good script for comparing RBG values?
The values are hexadecimal and I need to find a color that is closest to the one I'm comparing. I've tried a lot of stuff but I can't get the...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |