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: 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: Martin Trump on
> I'm using the following code to get a snapshot of the screen in a
> StdPicture object.
>
> http://www.devx.com/vb2themax/Tip/19172

Wow! What a chunk of code!

I think this fragment I have used could be adapted to your needs.

Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte,
ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

AppActivate getaviname
keybd_event vbKeyMenu, 0, 0, 0 ' Press ALT
keybd_event vbKeySnapshot, 0, 0, 0 ' Press Prntscr
keybd_event vbKeySnapshot, 0, 2, 0 ' Release Prntscr
keybd_event vbKeyMenu, 0, 2, 0 'Release ALT
pic2.Picture = Clipboard.GetData()
etc.
then save the picture

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

Comparing sizes of JPG's might be risky unless you know the level of
compression of each is the same.

HTH
From: Nobody on
"Martin Trump" <martin(a)wmeadow.demon.co.uk> wrote in message
news:6yaOm.25276$tF6.15319(a)newsfe28.ams2...
>> http://www.devx.com/vb2themax/Tip/19172
>
> Wow! What a chunk of code!
>
> I think this fragment I have used could be adapted to your needs.
>
> Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal
> bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
>
> AppActivate getaviname
> keybd_event vbKeyMenu, 0, 0, 0 ' Press ALT
> keybd_event vbKeySnapshot, 0, 0, 0 ' Press Prntscr
> keybd_event vbKeySnapshot, 0, 2, 0 ' Release Prntscr
> keybd_event vbKeyMenu, 0, 2, 0 'Release ALT
> pic2.Picture = Clipboard.GetData()
> etc.
> then save the picture

I could think of three issues with the code you posted:

1 - It would erase the clipboard, and this may annoy the user.

2 - The code you posted would capture the active window only, while the
BitBlt method would capture any window unless it's obscured by other
windows, in which case it captures the area in the desktop that it would
usually occupy.

3 - You need to use "Set" with any object assignment, so use "Set
pic2.Picture = Clipboard.GetData()".