From: H-Man on
On Fri, 20 Nov 2009 09:23:17 +0000, Dee Earley wrote:

> 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?

right, size alone won't tell you anything for sure. That's what a ahsh
function is for. Using a simple CRC32 function on the two data sets would
tell you pretty much right away if the data is the same.


--
HK
From: Dave O. on

"H-Man" <Spam(a)bites.fs> wrote in message
news:4b0ab6ba$0$65831$892e0abb(a)auth.newsreader.octanews.com...
> On Fri, 20 Nov 2009 09:23:17 +0000, Dee Earley wrote:
>
>> 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?
>
> right, size alone won't tell you anything for sure. That's what a ahsh
> function is for. Using a simple CRC32 function on the two data sets would
> tell you pretty much right away if the data is the same.
>
>
> --
> HK

Here's a thought, JPEGs being lossy tend to corrupt the image enough to make
comparisons tricky.
BMPs are not lossy but compared to JPEGs have huge file sizes.
Putting BMPs into a ZIP file can give as good, if not better compression
than JPEG and depending on which library you use (I use InfoZip) you can get
it to return the CRC of the file thus saving all that mucking about with CRC
routines.

So if he saves as BMP then sticks them into a ZIP file or files he can
compare easily and instead of a JPEG library he'll need a ZIP library, so
not really any change in overhead but a far simpler bit of coding.

Regards - Dave O.


From: Peter T on
"Martin Trump" <martin(a)wmeadow.demon.co.uk> wrote in message

>> 3 - You need to use "Set" with any object assignment, so use "Set
>> pic2.Picture = Clipboard.GetData()".
>
> Really? pic2.Picture = Clipboard.GetData() seems to work for me.

Yes both w/out Set work for me, in VBA too. I've never quite understood why.

Regards,
Peter T



From: Nobody on
"Peter T" <peter_t(a)discussions> wrote in message
news:%23V0DEoObKHA.4688(a)TK2MSFTNGP06.phx.gbl...
> "Martin Trump" <martin(a)wmeadow.demon.co.uk> wrote in message
>
>>> 3 - You need to use "Set" with any object assignment, so use "Set
>>> pic2.Picture = Clipboard.GetData()".
>>
>> Really? pic2.Picture = Clipboard.GetData() seems to work for me.
>
> Yes both w/out Set work for me, in VBA too. I've never quite understood
> why.

Looking at Object Browser(F2), the default property for both is "Handle". So
that line is equivalent to:

pic2.Picture.Handle = Clipboard.GetData().Handle


From: Peter T on
"Nobody" <nobody(a)nobody.com> wrote in message news:%
> "Peter T" <peter_t(a)discussions> wrote in message
>> "Martin Trump" <martin(a)wmeadow.demon.co.uk> wrote in message
>>
>>>> 3 - You need to use "Set" with any object assignment, so use "Set
>>>> pic2.Picture = Clipboard.GetData()".
>>>
>>> Really? pic2.Picture = Clipboard.GetData() seems to work for me.
>>
>> Yes both w/out Set work for me, in VBA too. I've never quite understood
>> why.
>
> Looking at Object Browser(F2), the default property for both is "Handle".
> So that line is equivalent to:
>
> pic2.Picture.Handle = Clipboard.GetData().Handle

AhHa, similar in VBA
MSForms.Image.Picture - Property Picture As StdPicture
StdPicture.Handle As OLE_HANDLE
Default member of stdole.StdPicture

Intuitively I guess .Handle = .Handle is a tad more efficient. Or is it, any
reason to use or not use Set?

Regards,
Peter T