Solved

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

Posted on 2003-11-04
14
672 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

626 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