Simple? Query the contents of an Imagebox

  • Thread starter Thread starter Phillip Taylor
  • Start date Start date
P

Phillip Taylor

I have an image box I set like this:

image1.image = my.resources.yes

or

image1.image = my.resources.no

How can I query which image is in the box later?

Neither

image1.image is my.resources.yes

or

image1.image.equals(my.resources.yes)

work.

Can anybody help?

Thanks

Phill
 
Phillip Taylor said:
I have an image box I set like this:

image1.image = my.resources.yes

or

image1.image = my.resources.no

How can I query which image is in the box later?

Neither

image1.image is my.resources.yes

or

image1.image.equals(my.resources.yes)

work.

Can anybody help?


The generated code is wrong. "Yes" must have been a function, not a
property. A property indicates that each time the same image is returned. In
fact, a new Image is created every time. Therefore, comparing the image in
the Control to the new Image from the ressource, will always return False.

Remember which image you assigned in a separate variable.


Armin
 
The generated code is wrong. "Yes" must have been a function, not a
property. A property indicates that each time the same image is returned. In
fact, a new Image is created every time. Therefore, comparing the image in
the Control to the new Image from the ressource, will always return False.

Remember which image you assigned in a separate variable.

Armin

It's got the property icon. What's more, it's generated automatically
from the properties page for the project. (The resources tab - each
resource gets a name under My.Resources.<auto_generated>). I
understand what your saying about the references not lining up because
it's not the same instance of the object.

However, it's basically flat out impossible for me to store the
original image description in a seperate variable. This is some of the
most complex code I've written and it's well tested so I can't afford
to change it and get it wrong. I don't want to get into the symantecs
of what the code does or whether it's good coding but basically I
cannot modify the code in the way you have suggested, which is a
shame.

However, let me explain what I'm trying to do. I have a user control I
wrote myself. When it is disabled, the images within the control do
not change. They still look colourful like this could be clicked on.
What I'm really going for is to have my controls OnEnabledChanged
value toggle between colourful and "Greyscale" style images but I
cannot compare the image to it's original value. Can anyone help
please?
 
Phillip Taylor said:
It's got the property icon. What's more, it's generated
automatically from the properties page for the project. (The
resources tab - each resource gets a name under
My.Resources.<auto_generated>). I
understand what your saying about the references not lining up
because it's not the same instance of the object.

However, it's basically flat out impossible for me to store the
original image description in a seperate variable. This is some of
the most complex code I've written and it's well tested so I can't
afford to change it and get it wrong. I don't want to get into the
symantecs of what the code does or whether it's good coding but
basically I
cannot modify the code in the way you have suggested, which is a
shame.

However, let me explain what I'm trying to do. I have a user control
I wrote myself. When it is disabled, the images within the control
do not change. They still look colourful like this could be clicked
on. What I'm really going for is to have my controls
OnEnabledChanged
value toggle between colourful and "Greyscale" style images but I
cannot compare the image to it's original value. Can anyone help
please?

If you wanted to compare images, you had to compare each pixel. In the Image
property, you will never know where it originally came from. As this
information is not available, you have to remember it anywhere.

Why do you need to know where the image came from? If you want to create a
grayscale image, you can take the image from the Image property.


Armin
 
If you wanted to compare images, you had to compare each pixel. In the Image
property, you will never know where it originally came from. As this
information is not available, you have to remember it anywhere.

Why do you need to know where the image came from? If you want to create a
grayscale image, you can take the image from the Image property.

Armin

I fixed Armin!!!!

I use image1.image.rawformat.equals(my.resources.yes.rawformat)

Thanks for your help dude, that got my cogs turning!

Phill
 
I fixed Armin!!!!

I use image1.image.rawformat.equals(my.resources.yes.rawformat)

Thanks for your help dude, that got my cogs turning!

Phill

no. i don't know what I'm talking about. that doesn't work
 
no. i don't know what I'm talking about. that doesn't work

I've written it myself now. Thanks for the help earlier. The benefit
of everyone this is the code:

Public Function CompareTwoImages(ByRef image1 As Image, ByRef
image2 As Image) As Boolean

If (image1.Height <> image2.Height) Then Return False
If (image1.Width <> image2.Width) Then Return False

'cast to bitmaps so we can have some functionality
Dim img1 As New Bitmap(image1)
Dim img2 As New Bitmap(image2)

'compare every single pixel individually.
For x As Int32 = 0 To img1.Width - 1
For y As Int32 = 0 To img1.Height - 1
If (img1.GetPixel(x, y) <> img2.GetPixel(x, y)) Then
Return False
Next
Next

Return True
End Function
 
Phillip Taylor said:
I've written it myself now. Thanks for the help earlier. The benefit
of everyone this is the code:

Public Function CompareTwoImages(ByRef image1 As Image, ByRef
image2 As Image) As Boolean

If (image1.Height <> image2.Height) Then Return False
If (image1.Width <> image2.Width) Then Return False

'cast to bitmaps so we can have some functionality
Dim img1 As New Bitmap(image1)
Dim img2 As New Bitmap(image2)

'compare every single pixel individually.
For x As Int32 = 0 To img1.Width - 1
For y As Int32 = 0 To img1.Height - 1
If (img1.GetPixel(x, y) <> img2.GetPixel(x, y)) Then
Return False
Next
Next

Return True
End Function

Comparing all Pixels should not have been a suggestion. :-)

I don't understand why you don't simply remember which image you stored
instead of producing a lot of code that additionally costs a lot of
CPU power.


Armin
 
Phillip Taylor schreef:
I have an image box I set like this:

image1.image = my.resources.yes

or

image1.image = my.resources.no

How can I query which image is in the box later?

Neither

image1.image is my.resources.yes

or

image1.image.equals(my.resources.yes)

work.

Can anybody help?

Thanks

Phill

In the image1.tag indicate which one is active i.e.

....
image1.image=my.resources.no
image1.tag = "no"
....

You can use the tag to store any arbitrary information.
 
Phillip Taylor schreef:






In the image1.tag indicate which one is active i.e.

...
image1.image=my.resources.no
image1.tag = "no"
...

You can use the tag to store any arbitrary information.

I am refering to the Image object, not the PictureBox Component. It
does not have a Tag property.
 
Back
Top