Solved

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

Posted on 2003-11-04
14
668 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Windows Script Host failed (Access is denied.) error 6 221
Not needed 13 119
What language/protocol is the Angular Chat? 2 83
VBA: Insert New column with specific format type 12 38
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

808 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