By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,533 Members | 1,497 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,533 IT Pros & Developers. It's quick & easy.

How to Compare Picture box's BackgroundImage Property

P: n/a

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.
--
Dino Buljubasic
Software Developer
http://rivusglobal.com
Nov 20 '05 #1
Share this Question
Share on Google+
14 Replies


P: n/a
Hello,

"Dino M. Buljubasic" <di*************@rivusglobal.com> schrieb:
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/dotn...magecompare.cs

Regards,
Herfried K. Wagner
--
MVP VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #2

P: n/a
Thanks Herfried,

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

Regards,

--
Dino Buljubasic
Software Developer
http://rivusglobal.com

"Herfried K. Wagner [MVP]" <hi*******@m.activevb.de> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hello,

"Dino M. Buljubasic" <di*************@rivusglobal.com> schrieb:
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/dotn...magecompare.cs

Regards,
Herfried K. Wagner
--
MVP VB Classic, VB.NET
http://www.mvps.org/dotnet

Nov 20 '05 #3

P: n/a
Hello,

"Dino M. Buljubasic" <di*************@rivusglobal.com> schrieb:
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
--
MVP VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #4

P: n/a
Hi again,

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

Regards,
Fergus
Nov 20 '05 #5

P: n/a
Cor
:-)))
Nov 20 '05 #6

P: n/a
Hello,

"Fergus Cooney" <fi******@tesco.net> schrieb:
[Algorithm for comparing bitmaps]
Hope this informs, if nothing else.


Are you sure that this is faster than comparing each pixel?

Regards,
Herfried K. Wagner
--
MVP VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #7

P: n/a
Hello,

"Fergus Cooney" <fi******@tesco.net> schrieb:
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
--
MVP VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #8

P: n/a
Hello,

"Cor" <no*@non.com> schrieb:
:-)))


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

Regards,
Herfried K. Wagner
--
MVP VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #9

P: n/a
Cor
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
Nov 20 '05 #10

P: n/a
Hi Cor,

"Cor" <no*@non.com> schrieb:
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
--
MVP VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #11

P: n/a
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,

--
Dino Buljubasic
Software Developer
http://rivusglobal.com

"Herfried K. Wagner [MVP]" <hi*******@m.activevb.de> wrote in message
news:ug**************@TK2MSFTNGP10.phx.gbl...
Hello,

"Fergus Cooney" <fi******@tesco.net> schrieb:
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
--
MVP VB Classic, VB.NET
http://www.mvps.org/dotnet

Nov 20 '05 #12

P: n/a
LOL

Fergus
Nov 20 '05 #13

P: n/a
Hello,

"Dino M. Buljubasic" <di*************@rivusglobal.com> schrieb:
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
--
MVP VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #14

P: n/a
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
Nov 20 '05 #15

This discussion thread is closed

Replies have been disabled for this discussion.