Following Code used to Remote Desktop Monitoring....
ImageCapture.java
1.This code client side code
2. This code Capture the current window screen and sends to particular server system .
import java.io.*;
import java.awt.*;
import java.awt.Image.*;
import java.net.*;
import java.io.File;
import java.util.*;
import java.lang.*;
import java.awt.Image;
import java.io.Serializable;
import java.applet.Applet;
import javax.swing.*;
import java.awt.*;
import java.io.*;
import java.awt.datatransfer.*;
import java.awt.event.*;
import javax.swing.filechooser.FileFilter;
import javax.swing.border.*;
import javax.swing.event.*;
import javax.swing.undo.*;
import javax.swing.colorchooser.ColorChooserComponentFactory;
import sun.beans.editors.StringEditor;
import javax.swing.plaf.MenuBarUI;
import javax.swing.text.*;
import javax.imageio.ImageIO;
import java.net.*;
import com.sun.image.codec.jpeg.*;
import java.awt.image.BufferedImage;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.*;
import java.awt.*;
import java.net.*;
import java.io.*;
import javax.imageio.ImageIO;
import java.awt.geom.*;
public class ImageCapture implements Runnable
{
boolean act=true;
public Robot robo;
byte [] dataone;
int count=0;
public BufferedImage myImage;
//public InetAddress multicastAddress;
public Socket socket;
Thread main;
public static void main(String args[])
{
try
{
ImageCapture img=new ImageCapture();
}
catch(Exception e)
{
System.out.println("Errr inImgcanvas "+e);
}
}
public ImageCapture()
{
try
{
robo=new Robot();
if(act==true)
{
main=new Thread(this);
main.start();
System.out.println("Started");
}
else
{
main.stop();
System.out.println("Stoped");
}
}
catch(Exception e)
{
System.out.println("Errr inImgcanvas cons "+e);
}
}
public void run()
{
try
{
for (;;)
{
//if(act==true)
{
System.out.println("Started");
myImage=robo.createScreenCapture(new Rectangle(0,0,800,800));
int x1=155;int y1=150;int x2=205;int y2=185;
int red = 255;
int green = 0;
int blue = 0;
int transparency =100;
Graphics graphics = myImage.getGraphics();
Color color = new Color(red, green,blue,255 * transparency/100);
graphics.setColor(color);
graphics.drawString("Screen Capture " +new java.util.Date(),50, myImage.getHeight() - 10);
int thumbWidth=500,thumbHeight=500;
double thumbRatio =(double)thumbWidth /(double)thumbHeight;
int imageWidth =myImage.getWidth(null);
int imageHeight=myImage.getHeight(null);
double imageRatio =(double)imageWidth / (double)imageHeight;
if (thumbRatio <imageRatio) {
thumbHeight =(int)(thumbWidth /imageRatio);
} else {
thumbWidth =(int)(thumbHeight *imageRatio);
}
BufferedImage thumbImage = new BufferedImage(thumbWidth,thumbHeight,BufferedImage.TYPE_INT_RGB);
Graphics2D graphics2D=thumbImage.createGraphics();
graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BILINEAR);
graphics2D.drawImage(myImage, 0, 0,thumbWidth,thumbHeight, null);
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream("screencapture.jpg"));
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam param= encoder.getDefaultJPEGEncodeParam(thumbImage);
int quality =Integer.parseInt("75");
quality = Math.max(0,Math.min(quality,100));
param.setQuality((float)quality / 100.0f,false);
encoder.setJPEGEncodeParam(param);
encoder.encode(thumbImage);
File file=new File("screencapture.jpg");
RandomAccessFile f=new RandomAccessFile(file,"r");
System.out.println("transmit len="+f.length());
byte [] data = new byte[(int)f.length()];
if(count++==0)
dataone=new byte[data.length];
f.read(data);
if(dataone.length!=data.length)
{
System.out.println("Transmitting");
socket = new Socket("localhost",8080);
ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
oos.writeObject(file);
}
dataone=data;
f.close();
file.delete();
main.sleep(2000);
}
}
}
catch(Exception e)
{
System.out.println("Errr in Imgcanvas thread "+e);
}
}
}
Monitor.java
This code read the client scree and displays the screening images...
import java.awt.image.BufferedImage;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.*;
import java.awt.*;
import java.net.*;
import java.io.*;
import javax.imageio.ImageIO;
import java.awt.geom.*;
import javax.swing.*;
public class Monitor
{
public static void main(String args[])throws Exception
{
JFrame f1=new JFrame();
JLabel jl3=new JLabel();
ServerSocket sck=new ServerSocket(8080);
f1.setSize(400,300);
f1.setVisible(true);
while(true)
{
f1.repaint();
Socket server=sck.accept();
ObjectInputStream entrada= new ObjectInputStream(server.getInputStream());
File file=(File)entrada.readObject();
Image image = ImageIO.read(file);
ImageIcon imgvar=new ImageIcon(image);
jl3.setIcon(imgvar);
f1.add(jl3);
} }
}
This following code to capture the client Screen and send it to the server.Server to Record the Screen on hard disk .This program to implement the Server socket concept.This code is very good one.here not implement Multi-threading.you have used to multi threading and captures all you client screen
1.This code client side code
2. This code Capture the current window screen and sends to particular server system .
import java.io.*;
import java.awt.*;
import java.awt.Image.*;
import java.net.*;
import java.io.File;
import java.util.*;
import java.lang.*;
import java.awt.Image;
import java.io.Serializable;
import java.applet.Applet;
import javax.swing.*;
import java.awt.*;
import java.io.*;
import java.awt.datatransfer.*;
import java.awt.event.*;
import javax.swing.filechooser.FileFilter;
import javax.swing.border.*;
import javax.swing.event.*;
import javax.swing.undo.*;
import javax.swing.colorchooser.ColorChooserComponentFactory;
import sun.beans.editors.StringEditor;
import javax.swing.plaf.MenuBarUI;
import javax.swing.text.*;
import javax.imageio.ImageIO;
import java.net.*;
import com.sun.image.codec.jpeg.*;
import java.awt.image.BufferedImage;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.*;
import java.awt.*;
import java.net.*;
import java.io.*;
import javax.imageio.ImageIO;
import java.awt.geom.*;
public class ImageCapture implements Runnable
{
boolean act=true;
public Robot robo;
byte [] dataone;
int count=0;
public BufferedImage myImage;
//public InetAddress multicastAddress;
public Socket socket;
Thread main;
public static void main(String args[])
{
try
{
ImageCapture img=new ImageCapture();
}
catch(Exception e)
{
System.out.println("Errr inImgcanvas "+e);
}
}
public ImageCapture()
{
try
{
robo=new Robot();
if(act==true)
{
main=new Thread(this);
main.start();
System.out.println("Started");
}
else
{
main.stop();
System.out.println("Stoped");
}
}
catch(Exception e)
{
System.out.println("Errr inImgcanvas cons "+e);
}
}
public void run()
{
try
{
for (;;)
{
//if(act==true)
{
System.out.println("Started");
myImage=robo.createScreenCapture(new Rectangle(0,0,800,800));
int x1=155;int y1=150;int x2=205;int y2=185;
int red = 255;
int green = 0;
int blue = 0;
int transparency =100;
Graphics graphics = myImage.getGraphics();
Color color = new Color(red, green,blue,255 * transparency/100);
graphics.setColor(color);
graphics.drawString("Screen Capture " +new java.util.Date(),50, myImage.getHeight() - 10);
int thumbWidth=500,thumbHeight=500;
double thumbRatio =(double)thumbWidth /(double)thumbHeight;
int imageWidth =myImage.getWidth(null);
int imageHeight=myImage.getHeight(null);
double imageRatio =(double)imageWidth / (double)imageHeight;
if (thumbRatio <imageRatio) {
thumbHeight =(int)(thumbWidth /imageRatio);
} else {
thumbWidth =(int)(thumbHeight *imageRatio);
}
BufferedImage thumbImage = new BufferedImage(thumbWidth,thumbHeight,BufferedImage.TYPE_INT_RGB);
Graphics2D graphics2D=thumbImage.createGraphics();
graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BILINEAR);
graphics2D.drawImage(myImage, 0, 0,thumbWidth,thumbHeight, null);
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream("screencapture.jpg"));
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam param= encoder.getDefaultJPEGEncodeParam(thumbImage);
int quality =Integer.parseInt("75");
quality = Math.max(0,Math.min(quality,100));
param.setQuality((float)quality / 100.0f,false);
encoder.setJPEGEncodeParam(param);
encoder.encode(thumbImage);
File file=new File("screencapture.jpg");
RandomAccessFile f=new RandomAccessFile(file,"r");
System.out.println("transmit len="+f.length());
byte [] data = new byte[(int)f.length()];
if(count++==0)
dataone=new byte[data.length];
f.read(data);
if(dataone.length!=data.length)
{
System.out.println("Transmitting");
socket = new Socket("localhost",8080);
ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
oos.writeObject(file);
}
dataone=data;
f.close();
file.delete();
main.sleep(2000);
}
}
}
catch(Exception e)
{
System.out.println("Errr in Imgcanvas thread "+e);
}
}
}
Monitor.java
This code read the client scree and displays the screening images...
import java.awt.image.BufferedImage;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.*;
import java.awt.*;
import java.net.*;
import java.io.*;
import javax.imageio.ImageIO;
import java.awt.geom.*;
import javax.swing.*;
public class Monitor
{
public static void main(String args[])throws Exception
{
JFrame f1=new JFrame();
JLabel jl3=new JLabel();
ServerSocket sck=new ServerSocket(8080);
f1.setSize(400,300);
f1.setVisible(true);
while(true)
{
f1.repaint();
Socket server=sck.accept();
ObjectInputStream entrada= new ObjectInputStream(server.getInputStream());
File file=(File)entrada.readObject();
Image image = ImageIO.read(file);
ImageIcon imgvar=new ImageIcon(image);
jl3.setIcon(imgvar);
f1.add(jl3);
} }
}
0 comments:
Post a Comment