PageRenderTime 446ms CodeModel.GetById 442ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/src/main/java/com/wet/wired/jrc/frame/capture/ScreenGrabber.java

http://java-remote-control.googlecode.com/
Java | 46 lines | 35 code | 11 blank | 0 comment | 0 complexity | 2a1e13e582f3cc8f06e7d4de9e93a63d MD5 | raw file
 1package com.wet.wired.jrc.frame.capture;
 2
 3import java.awt.Dimension;
 4import java.awt.Rectangle;
 5import java.awt.Robot;
 6import java.awt.Toolkit;
 7import java.awt.image.BufferedImage;
 8
 9import com.wet.wired.jrc.frame.Frame;
10
11public class ScreenGrabber implements FrameGrabber {
12
13	private Robot robot;
14	private Rectangle screenRectangle; 
15	
16	public ScreenGrabber() throws FrameCaptureException {
17		initialize();
18	}
19	
20	private void initialize() throws FrameCaptureException {
21		try{
22			robot = new Robot();
23			screenRectangle = new Rectangle(Toolkit.getDefaultToolkit ().getScreenSize());
24		} catch (Exception e) {
25			throw new FrameCaptureException("Failed to initialize ScreenGrabber",e);
26		}
27	}
28	
29	@Override
30	public Dimension getFrameSize() {
31		return screenRectangle.getSize();
32	}
33
34	@Override
35	public Frame grabFrame() {
36		BufferedImage grab = robot.createScreenCapture(screenRectangle);
37		int[] rawData = new int[screenRectangle.width*screenRectangle.height];
38		grab.getRGB(0,0,screenRectangle.width,screenRectangle.height,rawData,0,screenRectangle.width);
39		
40		Frame frame = new Frame(screenRectangle.width,screenRectangle.height);
41		frame.setData(rawData);
42		return frame;
43	}
44
45}
46