Link to home
Start Free TrialLog in
Avatar of darkshadow88
darkshadow88

asked on

How do I resize a screenshot to make it small enough to send over the internet?

I have a program that uses Winsock to obtain a screenshot from a remote computer.  The problem is, the screenshot is almost 1.5MB, which takes way too long to send.  Is there any way to resize the picture or remove color quality from within Visual Basic?  The code I am using to obtain the screenshot is as follows:

keybd_event vbKeySnapshot, 0, 0&, 0&
Avatar of NBrownoh
NBrownoh

ok this is what you can do
Heres the code

Private Sub Command1_Click()
    Clipboard.Clear
    Call keybd_event(VK_SNAPSHOT, 0, 0&, 0&)
    DoEvents
    Picture1.PaintPicture Clipboard.GetData, 0, 0,ResizeWidth, ResizeHeight
End Sub

All you need to do is set the resizewidth and resizeheight to what you want, say picture1.width and picture1.height, it might look a bit malresized but it fits into your picturebox
I would consider saving the screen shot into a compressed format, like jpeg.  See:
http://www.vbaccelerator.com/codelib/gfx/vbjpeg.htm
Avatar of darkshadow88

ASKER

Can you post an example of converting a bmp to jpg?
The link I posted provides an example.  Note that VB has no internal capabilities for converting to jpeg.  The above link uses a free jpeg library for saving to jpeg, and a class module that does all the work of using that jpeg library for you.
if you dont care about image quality that much just use the example i gave you, but save the image to a file then open that file and send it over tcp or whatever your using.  Adding jpeg compression/decompression if going to be some work, and the support site isnt too instructive last time i went there, about 3 years ago i think.
I have this code:

keybd_event vbKeySnapshot, 0, 0&, 0&
frmServer.pic1.PaintPicture Clipboard.GetData, 0, 0, 200, 150
SavePicture frmServer.pic1.Picture, "c:\sht.bmp"

but it does not work.  What is wrong with this code?
Also, is it possible to convert to 16 colors or monochrome?
keybd_event vbKeySnapshot, 0, 0&, 0&
DoEvents
frmServer.pic1.PaintPicture Clipboard.GetData, 0, 0, 200, 150
DoEvents
SavePicture frmServer.pic1.Image, "c:\sht.bmp"

do that instead, i tested it and it works, the picture is extremely small but it works.
>>is it possible to convert to 16 colors or monochrome

See that site above (vbaccelerator.com) for lots of advanced imaging techniques.  The code is not simple but that's the price you pay to get the functionality you want.

BTW, the key to the above was using the Image property of the picture object instead of its Picture property.  The Image property reflects all of the actual drawing that has been done to the picturebox control.  You can transfer this to the Picture property at any time by using:

pic1.Picture = pic1.Image
i cant find anything on converting color schemes like what you want, but another thing you need to do is set the pic1 auto resize property to true, if you dont do that then the image will be the size of the picturebox and not the size of the picture.
I now have this code:

keybd_event vbKeySnapshot, 0, 0&, 0&
DoEvents
frmServer.pic1.PaintPicture Clipboard.GetData, 0, 0, 4000, 3000
DoEvents
SavePicture frmServer.pic1.Image, "c:\sht.bmp"

When I look at the picture box on the server side, the image is there, but the file that is generated contains only a grey rectangle.

ASKER CERTIFIED SOLUTION
Avatar of NBrownoh
NBrownoh

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Auto redraw was, indeed, the problem.  Everything is now working correctly.  Thank you for your help.
cool, glad i could help.  If you have any more problems just let me know.