Solved

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

Posted on 2003-11-04
14
664 Views
Last Modified: 2013-11-13
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&
0
Comment
Question by:darkshadow88
  • 6
  • 5
  • 3
14 Comments
 
LVL 3

Expert Comment

by:NBrownoh
ID: 9680570
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
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 9680746
I would consider saving the screen shot into a compressed format, like jpeg.  See:
http://www.vbaccelerator.com/codelib/gfx/vbjpeg.htm
0
 

Author Comment

by:darkshadow88
ID: 9681280
Can you post an example of converting a bmp to jpg?
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 9681506
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.
0
 
LVL 3

Expert Comment

by:NBrownoh
ID: 9681612
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.
0
 

Author Comment

by:darkshadow88
ID: 9682536
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?
0
 

Author Comment

by:darkshadow88
ID: 9682549
Also, is it possible to convert to 16 colors or monochrome?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 3

Expert Comment

by:NBrownoh
ID: 9682616
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.
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 9682672
>>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
0
 
LVL 3

Expert Comment

by:NBrownoh
ID: 9682695
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.
0
 

Author Comment

by:darkshadow88
ID: 9682859
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.

0
 
LVL 3

Accepted Solution

by:
NBrownoh earned 50 total points
ID: 9682897
hehe, ok do this instead.

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

make sure the pic1 auto redraw value is set to true, that might cause the problem too
0
 

Author Comment

by:darkshadow88
ID: 9682920
Auto redraw was, indeed, the problem.  Everything is now working correctly.  Thank you for your help.
0
 
LVL 3

Expert Comment

by:NBrownoh
ID: 9682924
cool, glad i could help.  If you have any more problems just let me know.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

This article will show, step by step, how to integrate R code into a R Sweave document
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now