How to Compare Picture box's BackgroundImage Property

  • Thread starter Thread starter Dino M. Buljubasic
  • Start date Start date
D

Dino M. Buljubasic

I would like to be able to compare BackgroundImage Property of two picture
boxes on my form.

How can I do that?

I am using :

if (pctOne.BackgroundImage Is pctTwo.BackgroundImage) then
// blah, blah, blah
end if

, but this does not work.

Any help will be appreciated.
 
Hello,

Dino M. Buljubasic said:
I would like to be able to compare BackgroundImage Property of
two picture boxes on my form.

How can I do that?

I am using :

if (pctOne.BackgroundImage Is pctTwo.BackgroundImage) then
// blah, blah, blah
end if

, but this does not work.

The code above will compace the references represented by the
'BackgroundImage' properties. Do you want to compare the _images_
("bitmaps") or the _references_?

Comparing the images is really slow in VB.NET. It's better to use something
like this C# routine using pointers (*grml*):

http://www.palmbytes.de/content/dotnetmisc/dl/imagecompare.cs

Regards,
Herfried K. Wagner
 
Thanks Herfried,

I'd like to compare the bitmaps (or jpg). Is there a way to do that in
VB.net?

Regards,
 
Hello,

Dino M. Buljubasic said:
I'd like to compare the bitmaps (or jpg). Is there a way to do that in
VB.net?

Really slow: Loop through the 'Bitmap' object's pixels and compare the
colors at (x, y). You can get the color of the pixel at position (x, y) by
calling the 'Bitmap' objects's 'GetPixel' method.

Regards,
Herfried K. Wagner
 
Hi again,

Another way - a bit of a cheat - save both to disk and then do a file
compare. :-)

Regards,
Fergus
 
Hello,

Fergus Cooney said:
Another way - a bit of a cheat - save both to disk and then do a file
compare. :-)

Maybe it's even possible to save the bitmaps to 'FileStream's.

Regards,
Herfried K. Wagner
 
Hello,

Cor said:

It would be great if you quote the paragraph you are referring to so others
can understand what you mean.

Regards,
Herfried K. Wagner
 
Herfried,
I will keep it im mind something more, I dont like the way from long
messages where somewhere is some text but I will try to do it on a better
way.
For this one it was not by accident, it was very special. I don't want a
discussion with others.
grrrrrrrrrrrrrr :-) Is that enough in this situation?
Cor
 
Hi Cor,

Cor said:
I will keep it im mind something more, I dont like the
way from long messages where somewhere is some text
but I will try to do it on a better way.
For this one it was not by accident, it was very special.
I don't want a discussion with others.
grrrrrrrrrrrrrr :-) Is that enough in this situation?

;-)))

Regards,
Herfried K. Wagner
 
I think I am simply going to assign a tag value to each of my pictures and
each compare the tags.... simple, easy, fast :)

Thank you anyways,
 
Hello,

Dino M. Buljubasic said:
I think I am simply going to assign a tag value to each of
my pictures and each compare the tags.... simple, easy, fast :)

Great idea.

;-)))

Regards,
Herfried K. Wagner
 
Hi Herfried,

It sounds like a lot of work, and it is, but, as it's all being done at
the lowest level possible, it's very fast.

The disadvantage of pixel setting and getting is the travelling up and
down the layers of abstraction from VB through Win Api down to the boys who
are up to their knees in pixels. There's <so much> wrapping that it is, as you
said, really slow. I would imagine that the ratio is huge - several hundred
instructions per pixel.

The folding-of-complete-bitmaps method does more actual work on each
pixel, but with far less running up and down the layers ladder. Once down at
the blitting level, only a few instructions would be required per pixel,
further aided by the code being in the CPU's cache.

[Since writing the above, I went off to do some testing...]

I did some timing tests comparing the setting of a bitmap to a given
colour using FillRectangle versus the same using SetPixel. The differences
depend on the size of the bitmap: At 20x20 the Fill was 17 times quicker. At
100x100 it was 240 times quicker. At 400x400 it was 640 times quicker.

Folding operates on the binary-chop principle, eg 32 wide requires 5
folds, 1024 wide requires only double the effort. Given those figures, on a
largish bitmap folding is likely to be considerably faster and the bigger the
bitmap, the better the ratio.

But, hey, when you can use a Tag to compare two images, lol, both these
methods look very sledgehammer-like :-)

Regards,
Fergus
 
Back
Top