How to capture the current contents on the screen running under windows.
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Ali_Khan
Posted On:   Sunday, February 24, 2002 06:18 AM

I want to capture the current contents displayed on the screen under windows.

Re: How to capture the current contents on the screen running under windows.

Posted By:   Kiran_Kumar  
Posted On:   Monday, February 25, 2002 07:37 PM

Use the following code, it might help you.



import java.awt.*;

import java.awt.image.*;

import java.awt.FileDialog.*;

import com.sun.image.codec.jpeg.*;

import java.io.*;



public class TestScreen {

public void getScreenImage(String loc) {

Robot robot;

try {

robot = new Robot();

}

catch(Exception e) {

throw new RuntimeException("unable to instantiate Robot");

}

Image screen = robot.createScreenCapture(new Rectangle(266, 37, 500, 350));



try {


FileOutputStream fileStream = new FileOutputStream(loc);

BufferedReader in = new BufferedReader(new FileReader(loc));

PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(loc)));



JPEGEncodeParam encodeParam = JPEGCodec.getDefaultJPEGEncodeParam((BufferedImage)screen);


JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(fileStream);

encoder.encode((BufferedImage)screen,encodeParam);



FileInputStream fis=new FileInputStream(loc);

byte b[]=new byte[fis.available()];



DataInputStream dis=new DataInputStream(fis);

dis.readFully(b);

PrintStream ps=new PrintStream(new FileOutputStream(loc),true);

ps.write(b,0,b.length);

}

catch(Exception ex2) {


ex2.printStackTrace();

}

}



public void fileSave() {

FileDialog fd = new FileDialog(new Frame(),"Save File",FileDialog.SAVE);

fd.show();

String fileLocation = fd.getDirectory()+fd.getFile();

String fileName = fd.getFile();



if(!(fd.getDirectory()== null || fd.getFile()== null)) {



getScreenImage(fileLocation);

}

}

public static void main(String [] args) {

TestScreen ts = new TestScreen();

ts.fileSave();

}

}

Re: How to capture the current contents on the screen running under windows.

Posted By:   Eric_Chen  
Posted On:   Monday, February 25, 2002 09:20 AM

You would need to write native code and
hook with JNI.
About | Sitemap | Contact