Screen capture in REALbasic line

In this tutorial we will learn how to create a screen capture application in REALbasic. We will discover three different methods to grab the screen form Mac OS, Windows or Linux desktop and load it to Canvas Control. Watch it, learn it, enjoy it!

Screencapture on Mac using REALbasic

Before we will learn to the universal way (cross platform) to grab the screen and load it into Canvas Control in REALbasic we will look at screencapture, a Terminal command used to invoke the screen capture feature in Mac OS X. Using Shell Class we will execute a command that will capture the screen and save it on our system desktop. Add a PushButton to Window1 and in it Sub Action () enter:

1
2
3
Dim s As New Shell
 
s.Execute ("screencapture -S -x ~/Desktop/screenshot.jpg")

The screencapture utility is not very well documented to date. A list of options follows.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
-S      In window capture mode, capture the screen instead of the window.
-W      Start interaction in window selection mode.
-c      Force screen capture to go to the clipboard.
-i      Capture screen interactively, by selection or window. The control
        key will cause the screen shot to go to the clipboard. The space key 
        will toggle between mouse selection and window selection
        modes.  The escape key will cancel the interactive screen shot.
-m      Only capture the main monitor, undefined if -i is set.
-s      Only allow mouse selection mode.
-w      Only allow window selection mode.
-x      Do not play sounds.
-C      Capture the cursor as well as the screen.  Only allowed in non-interactive modes.
-t      Image format to create, default is png.
file    where to save the screen capture

Screencapture on Windows using REALbasic

We can also try to grab the screen by simulating PrtSc key click. Add to Window1 a PushButton Control and Canvas Control. Now in PushButton Sub Action () enter:

1
2
3
4
5
6
7
Dim c As New Clipboard
 
Declare Sub keybd_event Lib "User32" ( keyCode as Integer, scanCode as Integer, flags as Integer, extraData as Integer )
 
keybd_event( &h2C, 0, 0, 0 ) //simulate pressing the PrtSc key
 
if c.PictureAvailable then Canvas1.Backdrop = c.Picture //load picture to Canvas Control

Screencapture on Linux using REALbasic

This method will work on Linux, Mac and Windows. Add to Window1 a PushButton Control and Canvas Control. Now in PushButton Sub Action () enter:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Dim r As RGBSurface
Dim screenshot As Picture
 
screenshot = New Picture (Canvas1.Width, Canvas1.Height, 32)
 
r = screenshot.RGBSurface
 
for i as integer = 0 to width
  for j as integer = 0 to height
    r.pixel(i, j) = system.pixel(i, j)
  next
next
 
Canvas1.Graphics.Drawpicture screenshot, 0, 0

Image manipulation in REALbasic

If you are creating a screen capture application in REALbasic you probably like to know how to open a image, how to fit graphic to canvas, how to crop the picture or display scaled image. In my earlier tutorial “Creating ImageViewer in REALbasic” you can find all answers on these questions.

Author: Jakub Pawlak

I'm interested in all. Currently working on the development of TUTSPOLIS and I hope that in near feature the project will be successful.

4 Responses to “Screen capture in REALbasic”

  1. fra says:

    can only make the capture of the program? windows

  2. Jakub Pawlak says:

    I don’t use MS Windows but I think that there is a option to get a screen shot form program window. We must simulate pressing the PrtSc key + Control Key (keybd_event(17,29,0,0)).

    On mac we can grab a screen shot form program window using command:

    screencapture -W ~/Desktop/screenshot.jpg

  3. Steve says:

    The Windows command keybd_event(17,29,0,0) does not work.

    Is there a way to take a Windows screen shot of the program window without placing and grabbing the information from the clipboard?

  4. Jakub Pawlak says:

    The last method Screencapture on Linux using REALbasic works on Windows too but it’s not perfect. REALbasic don’t offer this kind of option so the best way is calling some Windows declarations.

Leave a Reply

Copyrights (c) TUTSPOLIS | Powered by Wordpress MU | Inspired at Elegant Themes designed by qbap (HTML5 & CSS3)