Jump to content

Capturing the screen


Jack

Recommended Posts


//BY USING THIS CODE YOU AGREE THAT NONE OF THE CODE WILL BE USED IN A MALICIOUS WAY.

import java.awt.AWTException;

import java.awt.Rectangle;

import java.awt.Robot;

import java.awt.Toolkit;

import java.awt.image.BufferedImage;

import java.io.File;

import java.io.IOException;

import javax.imageio.ImageIO;

public class ScreenCap {

public ScreenCap()

{

}

public void screenShot(String fileName, String destination) throws IOException, AWTException

{

try

{

Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());

BufferedImage capture = new Robot().createScreenCapture(screenRect);

File outputfile = new File(destination+fileName+".png");

ImageIO.write(capture, "png", outputfile);

}

catch (IOException | AWTException e) {

e.printStackTrace();

}

}

}


try

{

sc.screenShot("MyScreenShot", "C:\\Users\\<INSERT USERNAME HERE>\\OSBot\\");

}

catch (IOException | AWTException e)

{

e.printStackTrace();

}

  • Like 2
Link to comment
Share on other sites

Awesome thanks!! I was actually wondering how to do this earlier in the day tongue.png. I'll test it and then integrate it into my remote access function for my essence mining script.

Although... your second try-catch clause is a bit redundant... tongue.png

The second one is how you access the screen shot in your main class. If you don't surround it with try/catch, it will crash your whole program. :)

Link to comment
Share on other sites

 

Awesome thanks!! I was actually wondering how to do this earlier in the day tongue.png. I'll test it and then integrate it into my remote access function for my essence mining script.

Although... your second try-catch clause is a bit redundant... tongue.png

The second one is how you access the screen shot in your main class. If you don't surround it with try/catch, it will crash your whole program. smile.png

 

 

The only way the exception can be thrown is if one of the calls inside the screenShot method throws an exception, but it will be caught by the handler inside that method. Can you give me a scenario in which an exception fails to be caught by the handler inside screenShot method but will be caught by the outer one? I can't seem to think of one lol... maybe I'm just missing something :P. But yeah it's a really nice piece of code. Thanks for sharing :D

 

Eric

Link to comment
Share on other sites

nice  i made one few days ago anyway thanks :)

i would suggest you add something to change the file's name each time it saves,

i usually just add the current time and date and time when file was saved e.g. "sceenshot2013-07-13 12 37 26 AM"

this is how i do it


SimpleDateFormat format = new SimpleDateFormat(yyyy-MM-dd HH mm ss a);
Calender calender = Calender.getInstance(); 
File outputfile = new File(destination+fileName+format.format(calender.getTime())+".png");

this will help a lot of people happy.png

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 weeks later...

use this to make a randoms data collector. snapshots and collects ids for the npcs/objects/etc.

Your sig bothers me.

public class Haters {

	public void handle(String name) {
		switch(name) {
		case "Kati":
			log("Gg.");
			System.exit(0);
			break;
		case "XavierM":
			log("Your scripts are overpriced.");
			break;
		case "Led Zeppelin":
			log("Post whore.");
			break;
		default: 
			log("This script isn't for you.");
			break;
		}
	}

	public void log(String text) {
		System.out.println(text);
	}

	public static void main(String... args) {
		Haters haters = new Haters();
		haters.handle(client.getBot().getUsername());
	}

}
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...