From: VbPro7 on
Hi VB lovers,

I'm using the following code to get a snapshot of the screen in a
StdPicture object.

http://www.devx.com/vb2themax/Tip/19172


However my problem is I need to get the space used (no of bytes) by the
image in memory. Is this possible? If not I would like to convert the image
into a JPG file and then get the size of file in bytes.
Size itself is not required actually. I just want to compare two images and
see if they are the same. The only way I can think of is to compare there
size/space in memory or disk. If there is another efficient way to do this
please advise.

Thanks

From: Dee Earley on
On 20/11/2009 02:04, VbPro7 wrote:
> Hi VB lovers,
>
> I'm using the following code to get a snapshot of the screen in a
> StdPicture object.
>
> http://www.devx.com/vb2themax/Tip/19172
>
> However my problem is I need to get the space used (no of bytes) by the
> image in memory. Is this possible? If not I would like to convert the
> image into a JPG file and then get the size of file in bytes.
> Size itself is not required actually. I just want to compare two images
> and see if they are the same. The only way I can think of is to compare
> there size/space in memory or disk. If there is another efficient way to
> do this please advise.

No, you can not relay on size to determine if they are the same.
Nor can you rely on different (non bitmap) binary data to say they are
different.

Bitmaps in memory are a fixed (height x width x bytes per pixel) +
header (with a few caveats for odd sizes and bit depths)
Once compressed, the final image data may contain other data so you are
unlikely to get exactly the same data for multiple encodes of the same
image.

The only way to reliably tell is to do a pixel by pixel comparison.
If the images will have been subject to lossy compression, you will have
to have a tolerance in there as well.

What are you actually trying to achieve by seeing if the screen has changed?

--
Dee Earley (dee.earley(a)icode.co.uk)
i-Catcher Development Team

iCode Systems
From: Dave O. on

"Dee Earley" <dee.earley(a)icode.co.uk> wrote in message
news:Ox51$IcaKHA.616(a)TK2MSFTNGP04.phx.gbl...

> The only way to reliably tell is to do a pixel by pixel comparison.
> If the images will have been subject to lossy compression, you will have
> to have a tolerance in there as well.

A while back I needed to compare bitmaps quickly and found that if I
combined 2 bitmaps using XOR (probably*) then if the pictures were identical
the result was pure black, then all I had to do was to zip through the
pixels of a single image looking for any non-zero value.
If the image is large you can save a bit of time by taking one half of the
result and XOR it with the other half, then repeat until down to a few
thousand pixels, again it will be all black if there were no non-black
pixels. Trial & error is probably the only way to find the optimum for
this.
Of course if the images were lossy such as JPEGs then it does get a lot
trickier as you'll get near black values, but that might be adequate to show
close similarity.

Another possibility that is best if you need to compare an image with
several others is to take the CRC of the images.

* Not sure it was XOR, could have been any logical operation and I don't
have the code to hand.

Dave O.


From: Nobody on
See this post, which gets the contents of a PictureBox as byte array. The
PictureBox AutoRedraw must be True. I believe you can adapt it to what you
need. I have made another that works regardless AutoRedraw property, but
it's few percentage points slower. That one uses BitBlt to copy PictureBox
contents to the compatible DC, instead of using the PictureBox autoredarw
bitmap itself.

http://groups.google.com/group/microsoft.public.vb.general.discussion/msg/9fafb6cfebff120e



From: Larry Serflaten on

"Dave O." <nobody(a)nowhere.com> wrote

> A while back I needed to compare bitmaps quickly and found that if I
> combined 2 bitmaps using XOR (probably*) then if the pictures were identical
> the result was pure black, then all I had to do was to zip through the
> pixels of a single image looking for any non-zero value.
> If the image is large you can save a bit of time by taking one half of the
> result and XOR it with the other half, then repeat until down to a few
> thousand pixels, again it will be all black if there were no non-black
> pixels. Trial & error is probably the only way to find the optimum for
> this.
> Of course if the images were lossy such as JPEGs then it does get a lot
> trickier as you'll get near black values, but that might be adequate to show
> close similarity.
>
> Another possibility that is best if you need to compare an image with
> several others is to take the CRC of the images.
>
> * Not sure it was XOR, could have been any logical operation and I don't
> have the code to hand.


I seem to recall a similar discussion...
http://groups.google.com/group/microsoft.public.vb.general.discussion/browse_thread/thread/a294f7e4aba0be1f/82bf4b082ec1c518?hl=en#82bf4b082ec1c518

"A while back" ? How about 8 years! <g>

LFS