Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (120)
games submitted by our members
Games in WIP (577)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Can I scan the screen or get a screenshot of my screen within Java?  (Read 1424 times)
0 Members and 1 Guest are viewing this topic.
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Posted 2006-10-18 17:57:33 »

I'm making a program to save certain keyboard or mouse actions you have done on your computer and reproduce them for you, helping out with a lot of things like mundane multimedia tasks and whatnot. I want you to be able to provide conditionals that will cause the program to produce certain actions, and these conditionals I want to rely solely on what is being displayed on your monitor.

Like, for example, I want the program to automatically log in to something for me once it opens, like JGO. It would need to scan the screen to see if it perhaps had the JGO banner in the expected place. If it did, it would automatically click in the login box, type out my name, then the password box and type out my password.

Yes, pretty ambitious, but I've got pretty much everything working already. I'm just wondering if there's some way to return what's being displayed as a BufferedImage, or to get a screenshot of it, at least, which may be a little processor intensive but it would certainly work.

Any ideas? Thanks guys.

See my work:
OTC Software
Offline woogley
« Reply #1 - Posted 2006-10-18 18:32:43 »

Robot.createScreenCapture(Rectangle)
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #2 - Posted 2006-10-18 18:48:23 »

Amazingly, I was already using Robot and didn't see that. Thanks very much.

Any idea how costly this operation is?

See my work:
OTC Software
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline woogley
« Reply #3 - Posted 2006-10-18 19:13:50 »

try out this test:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
import java.awt.*;
public class ScreenTest {
   public static void main(String args[]) {
      try {
         long now = System.currentTimeMillis();
         long ms = 0;
         Robot r = new Robot();
         Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
         Rectangle rect = new Rectangle(0,0,d.width,d.height);
         int count = 0;
         while (ms < 5000) {
            r.createScreenCapture(rect);
            ms+=(System.currentTimeMillis()-now);
            now = System.currentTimeMillis();
            count++;
         }
         System.out.println(count+" screenshots taken in "+(ms/1000.0)+" seconds");
      }
      catch (AWTException e) {
         e.printStackTrace();
      }
   }
}


for me I get about 14 screen captures per second on a 1024x768 screen. if you already have a presumed position for, say, the JGO banner, you can just use a smaller Rectangle for the screen capture and it should be alot faster than taking an ENTIRE screenshot
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #4 - Posted 2006-10-18 23:36:19 »

Ooh yeah, that's working really fast. I just have the user specify a certain rectangle that they want to search for, generally not larger than 50x50 pixels. 50x50 pixels goes really really fast. I can also put in the option to scan the screen for certain patterns, and therefore it would work across multiple resolutions, at least somewhat (look for the text box pattern, because it will always be the same size, etc.)

I wonder if there would be any way to get this to work flawlessly aside from forcing a resolution change. The windows will obviously move around and be in different places depending on resolution, even depending on computer. I suppose I could do something called findWindow() function that finds the window in question so it is only performed once to get a relative position, then smaller screen analysis can be performed. But can you think of another way to do this?

See my work:
OTC Software
Offline Abuse

JGO Knight


Medals: 13


falling into the abyss of reality


« Reply #5 - Posted 2006-10-19 00:16:53 »

Hook into the win32 api?!

Grabbing a screenshot and trying to derive what is where is a completely backward way of doing it.

You code is going to be platform specific anyway, so you might as well make use of the underlying api's provided to fulfill the exact feature you desire.

You never know, there may already be a java wrapper around for querying the active processes and/or window handles that are currently active.

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline woogley
« Reply #6 - Posted 2006-10-19 02:30:59 »

abuse is right, there are 100's of things that can get in the way with the screen capture method. the user can change the size of the titlebar text, which can throw everything off, for example..
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #7 - Posted 2006-10-19 23:13:39 »

Yeah, this is wholly true, but even if I could contact Windows does that mean that I could have Internet Explorer return to me its window size, font size, locations of text fields, etc.? I feel like even if I could do that it would just because program specific. I want this to be functionable through any program as long as the user saves a set of actions depending on different highlights on their screen.

See my work:
OTC Software
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (52 views)
2014-10-17 03:59:02

Norakomi (42 views)
2014-10-16 15:22:06

Norakomi (32 views)
2014-10-16 15:20:20

lcass (37 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (66 views)
2014-10-14 00:35:47

TehJavaDev (59 views)
2014-10-14 00:32:37

BurntPizza (73 views)
2014-10-11 23:24:42

BurntPizza (45 views)
2014-10-11 23:10:45

BurntPizza (85 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!