January 2005
Intermediate to advanced
256 pages
6h 34m
English
One frequently useful source of image data is, unsurprisingly, the screen—or screens, if you’re so fortunate. Each screen is represented by an object that can give you its current contents, though it takes a little work to do anything with it.
ScreenToPNG, shown in Example 5-5, is a headless application that starts up,
grabs the screen, and writes out the image to a
PNG file called
screen.png.
I use PNG for screenshots because it’s lossless, widely supported, compressed, and patent-unencumbered.
Example 5-5. Grabbing screen pixels
package com.oreilly.qtjnotebook.ch05; import quicktime.*; import quicktime.std.*; import quicktime.std.image.*; import quicktime.qd.*; import quicktime.io.*; import quicktime.util.*; import com.oreilly.qtjnotebook.ch01.QTSessionCheck; public class ScreenToPNG extends Object { public static void main (String[ ] args) { new ScreenToPNG( ); } public ScreenToPNG( ) { try { QTSessionCheck.check( ); GDevice gd = GDevice.getMain( ); System.out.println ("Got GDevice: " + gd); PixMap pm = gd.getPixMap( ); System.out.println ("Got PixMap: " + pm); ImageDescription id = new ImageDescription (pm); System.out.println ("Got ImageDescription: " + id); QDRect bounds = pm.getBounds( ); RawEncodedImage rei = pm.getPixelData( ); QDGraphics decompGW = new QDGraphics (id, 0); QTImage.decompress (rei, id, decompGW, bounds, 0); GraphicsExporter exporter = new GraphicsExporter (StdQTConstants4.kQTFileTypePNG); exporter.setInputPixmap ...Read now
Unlock full access