<- previous    index    next ->

Lecture 19a, Capturing Screen


The Java 3D code SphereMotion.java
keeps moving. Yet, it can be captured, as seen by the file
SphereMotion.jpg



Note that the red and green dots are not planets but are the
position of the lights that are moving.


The method of capturing using external tools is operating system
dependent. There are many tools and methods for every operating
system, only one method is presented for each operating system.

On Microsoft Windows I make the window to be captured active by
clicking in the blue bar at the top of the window. Then I press
and hold the "alt" key while pressing and releasing the
"print scr" key. This captures the active window in the Microsoft
cut-and-paste buffer.

Now I execute PaintShopPro and click on the "edit" menu and drag
to "paste as new image" then release. At this point I may change
the size of the image or crop to a selected area or make other
modifications. To save the, possibly modified, image I use
"save as" and select the saved format, e.g. .jpg, .gif or other.
Then select the directory where the image is to be saved and
save the file.

On X Windows systems which include Unix, Linux and others,
I open a shell window and make it small in the lower right hand
corner of the screen. I "cd" to the directory where the file
containing the image is to be stored.

I then move the window to be captured to the upper left hand corner
of the screen so there is no overlap.

In the shell window I type  "import name.jpg" and then left click
in the window to be captured. If sound is turned on there is one beep
when the capture starts and a second beep when capture is finished.
File types of at least .jpg, .png and .gif are recognized.

Then I do the cleanup: "gimp name.jpg" two windows come up,
one with tools, one with my captured image. I click on
dashed-square-box and place dashed line around the part
of the image I want. Then click on "image" menu and move
down to "crop to selection." Next, if I want a different
size, click on "image" menu and move down to "canvas size".
Now you can change horizontal and vertical size by
pixel or percentage. Be sure to use "file" then "save"
in order to keep you modifications.

The program "xv" can be used to display many image formats.
The command  "xv name.jpg" will display the image captured by the
procedure above.

Your browser can display and print images.
Just use   file:///home/your-directory/name.jpg
Or, file:///some-directory  to see all the files, then navigate and
double click to view a graphics file.

On Microsoft Windows, file:///C:/documents and settings/user/name.jpg

Image file formats provide a range of compressions and thus a range
of sizes. The quality of the program writing the image file format
can also make a big difference. For example, to write a fully compressed
 .gif file requires a license whereas a program can write a .gif file
that can be read by other applications and not use the proprietary
part of the compression.

Below is the same, large, image captured by "import" as .jpg, .png and
.gif. The sizes in bytes are respectively 39,098 , 11,490 and 329,115 .

These take a while to display, thus only the .jpg is shown:


 

The source code that you may get and put inside your application
includes:

www.ijg.org  Independent Jpeg Group   /files  get jpegsrc.v6b.tar.gz

www.filelibrary.com/Contents/DOCS/101/new.html  get  jpeg6b.zip

libpng.sourceforge.net links to download

www.libpng.org/pub/png  send you to sourceforge


Next: For the real GUI programmer, you want to build into your
application the ability to directly write out some image file
format. The code needed to capture the pixels from the screen
in your program depend on language and toolkit, not on operating
system. Thus, you can write portable code that outputs various
image file formats.

The following demonstrates basic capturing pixels, formatting and
writing the file. Modify to suit your needs. The examples cover
OpenGL, Java and X Windows. These happen to use the legal code
to do .gif output. Substitute .jpg, .png or other as you desire.
Note that the "decorations" put on by the window manager are not
part of your window. You only get out the pixels your application
writes.


w1gif.c w1.c with .gif output writes w1gif.gif



Hex dump of the above file.
Note readable file type, GIF89a, width and height, little endian
hexadecimal  00C5 by 007A, mostly unused color table.

A color table is an indexed list of colors, e.g.

color
index  R   G   B
  0   255  0   0
  1    0  255  0
  2    0   0  255
  3   200 200 200

Image byte values  0 0 1 3 2 2 2
would give pixels red, red, green, grey, blue, blue blue.
Note that in this simple case, only 256 colors are available for
any specific image. 8-bits replaces 24-bits for a 3-to-1 compression.
The image byte values may be further compressed by run length
encoding or other methods. 

Ugh, this version does not build the color table, it basically tests
background, that will come out white, and other that will come out black.

w1glgif.c w1gl.c with .gif output writes w1glgif.gif



Hex dump of the above file.

color tables

    <- previous    index    next ->

Other links

Many web sites on Java GUI, AWT, Swing, etc.
Many web sites on Python wx, tk, qt, etc.

Go to top