对于遵循X11标准的操作系统(Linux,FreeBSD,Solaris等),我们可以通过JavaCV和FFmpeg这样实现:
import com.googlepre.javacv.*;public class ScreenGrabber { public static void main(String[] args) throws Exception { int x = 0, y = 0, w = 1024, h = 768; // specify the region of screen to grab FFmpegframeGrabber grabber = new FFmpegframeGrabber(":0.0+" + x + "," + y); grabber.setFormat("x11grab"); grabber.setImageWidth(w); grabber.setImageHeight(h); grabber.start(); Canvasframe frame = new Canvasframe("Screen Capture"); while (frame.isVisible()) { frame.showImage(grabber.grab()); } frame.dispose(); grabber.stop(); }}我不了解Windows或Mac OS
X,但我怀疑我们需要直接访问本机API。不过,JavaCPP可以帮助实现这一点。



