Solved

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

Posted on 2003-11-04
14
667 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This article will show, step by step, how to integrate R code into a R Sweave document
The purpose of this article is to demonstrate how we can use conditional statements using Python.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

815 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

12 Experts available now in Live!

Get 1:1 Help Now