Find interesting stuff in Java, PHP and Dot Net.
Stop writing good code; Start writing Innovative code.
This site is from FUTURE. Science is powerful, but it cannot explain everything.
This site is for smart Primates & ROBOTS only (oh and A L I E N S).
Pages
- Home
- Send problem from my FaceBook Page
- Your FB bio/friends
- Auto Resume Broken File Uploader
- Screen Recorder
- Facebook App
- Screencast with Audio Capture
- Web Page Screen Capture As Image
- Add Watermark In Video
- Unique Code
- PDF Merger
- Unique Software
- Latest Posts
- Arbitrary Text in PDF
- MY ANDROID APP
- Torch in Android
Search This Blog
Top Ads
Tuesday, April 13, 2010
Friday, April 9, 2010
Screen capture with mouse position
Here I am showing, that how can get screen shot with mouse pointer position.
This is the small 10% part of VIDEO RECORDING of your desktop activity.
import java.awt.AWTException;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.Polygon;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.OutputStream;
import java.io.File;
import javax.imageio.ImageIO;
// Screen capture with mouse position.
// Date: 2:22 PM Wednesday Mar/24/2010
class GetScreenShot implements Runnable {
private Robot robot;
private Rectangle r;
private String filename,seq;
private int num,maxZero;
public GetScreenShot() {
try{
robot = new Robot();
num=1;
maxZero = 11;
seq = "";
}
catch(Exception ex1) {
ex1.printStackTrace();
}
}
public void run() {
while(true) {
try {
System.out.println(num);
String numSt=num+"";
int i;
for(i=1;i<=maxZero -numSt.length();i++) {
seq=seq+"0";
}
seq=seq+num+".jpg";
filename=seq;
r=new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
File file = new File(filename);
BufferedImage bf=null;
bf=captureScreen(r);
ImageIO.write(bf, "JPEG", file);
num++;
seq="";
Thread.sleep(9);
}
catch(Exception ee){
System.out.println(ee.toString());
}
}
}
public BufferedImage captureScreen(Rectangle recordArea) {
Point mousePosition = MouseInfo.getPointerInfo().getLocation();
BufferedImage image = robot.createScreenCapture(recordArea);
Polygon pointer = new Polygon(new int[]{0,16,10,8},new int[]{0,8,10,16},4);
Polygon pointerShadow = new Polygon(new int[]{6,21,16,14},new int[]{1,9,11,17},4);
Graphics2D gr12D = image.createGraphics();
gr12D.translate(mousePosition.x,mousePosition.y);
gr12D.setColor(new Color(100,100,100,100) );
gr12D.fillPolygon(pointerShadow);
gr12D.setColor(new Color(100,100,255,200) );
gr12D.fillPolygon(pointer);
gr12D.setColor(Color.red);
gr12D.drawPolygon(pointer);
gr12D.dispose();
return image;
}
}
public class ScreenCapWithMousePos {
public static void main(String ss[]) {
GetScreenShot gs=new GetScreenShot();
Thread thread1 = new Thread(gs);
thread1.start();
}
}
This is the small 10% part of VIDEO RECORDING of your desktop activity.
import java.awt.AWTException;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.Polygon;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.OutputStream;
import java.io.File;
import javax.imageio.ImageIO;
// Screen capture with mouse position.
// Date: 2:22 PM Wednesday Mar/24/2010
class GetScreenShot implements Runnable {
private Robot robot;
private Rectangle r;
private String filename,seq;
private int num,maxZero;
public GetScreenShot() {
try{
robot = new Robot();
num=1;
maxZero = 11;
seq = "";
}
catch(Exception ex1) {
ex1.printStackTrace();
}
}
public void run() {
while(true) {
try {
System.out.println(num);
String numSt=num+"";
int i;
for(i=1;i<=maxZero -numSt.length();i++) {
seq=seq+"0";
}
seq=seq+num+".jpg";
filename=seq;
r=new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
File file = new File(filename);
BufferedImage bf=null;
bf=captureScreen(r);
ImageIO.write(bf, "JPEG", file);
num++;
seq="";
Thread.sleep(9);
}
catch(Exception ee){
System.out.println(ee.toString());
}
}
}
public BufferedImage captureScreen(Rectangle recordArea) {
Point mousePosition = MouseInfo.getPointerInfo().getLocation();
BufferedImage image = robot.createScreenCapture(recordArea);
Polygon pointer = new Polygon(new int[]{0,16,10,8},new int[]{0,8,10,16},4);
Polygon pointerShadow = new Polygon(new int[]{6,21,16,14},new int[]{1,9,11,17},4);
Graphics2D gr12D = image.createGraphics();
gr12D.translate(mousePosition.x,mousePosition.y);
gr12D.setColor(new Color(100,100,100,100) );
gr12D.fillPolygon(pointerShadow);
gr12D.setColor(new Color(100,100,255,200) );
gr12D.fillPolygon(pointer);
gr12D.setColor(Color.red);
gr12D.drawPolygon(pointer);
gr12D.dispose();
return image;
}
}
public class ScreenCapWithMousePos {
public static void main(String ss[]) {
GetScreenShot gs=new GetScreenShot();
Thread thread1 = new Thread(gs);
thread1.start();
}
}
Subscribe to:
Posts (Atom)