• Post Reply Bookmark Topic Watch Topic
  • New Topic

capture system screen to a gif file![immdtly.]  RSS feed

netharam ram
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I want to capture the system screen & save it as a gif file,is it possible in java.I want to capture it for every user-defined seconds.This should be done without any key press or user-action.This capture should be done even without the notice of the current user.
Happy middling with java.
Rob Ross
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you building some kind of spy-tool Nethram?
Also, there really is no need to include words like "immediately" in your header. First, people are NOT going to answer you any faster. People come and go, most browse, and some people actively look for questions to answer. I answer questions as I find them, regardless of whether someone has written "URGENT" or RESPOND NOW or anything like that. In fact, I find it a little rude when people do that, but that's just my personal opinion.
To answer your questions though, I think java.awt.Robot.createScreenCapture() will work for you. You can create a background thread that snapshots the screen every N seconds as you like, and saves it to an image buffer. Other threads can then read from it, or save it , or send it somewhere, or do whatever you can do with an image.
Good luck.
Matt Payne
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
* ScreenCaptureDemo.java - demos screen captures with the Robot class. Has small bug, but works.
* Created on June 29, 2002, 6:11 PM
import javax.swing.*;
import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.print.*;
import com.sun.image.codec.jpeg.*;
* @author payne
public class ScreenCaptureDemo {

/** Creates a new instance of ScreenCaptureDemo */
public ScreenCaptureDemo() {

public static void main(String[] arg) {
JFrame jf = new JFrame("A frame");
Container c = jf.getContentPane();
c.setLayout(new FlowLayout());
c.add(new JButton("Robot screen capture demo based on"));
c.add(new JButton("http://www.java-conf.gr.jp/archives/servlet-ml/msg01910.html"));
c.add(new JButton("which was found with searches on Google.com"));

Dimension d = jf.getSize();
int hFudgeFactor=30; // getSize() doesn't get the whole size
Rectangle rect1 = new Rectangle(d.width, d.height+hFudgeFactor);
Graphics2D g = null;
Image im = null;
BufferedImage img = null;

try {
Robot r1 = new Robot();
im = r1.createScreenCapture(rect1);
// make an image (img) to save im into
img = new BufferedImage(d.width,d.height+hFudgeFactor, BufferedImage.TYPE_INT_RGB);
g = img.createGraphics(); // We'll speak to img via a graphics object
g.drawImage(im, null, null); // draw the im into g

// Encode the off screen image into a GIF and save it to a file
FileOutputStream out = new FileOutputStream("/tmp/x.jpg");
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);

} catch (Exception e) {


  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!