Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (595)
Games in Android Showcase (169)
games submitted by our members
Games in WIP (648)
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  
  take screenshots  (Read 2096 times)
0 Members and 1 Guest are viewing this topic.
Offline mill

Junior Devvie

popcorn freak

« Posted 2003-04-29 18:51:34 »

i continue to spit out small useful stuff that might interest someone. again, nothing fancy.

i'm getting lots of useful stuff in my Tools class now.. might release a lib some day.

public static void takeScreenShot(String filename, Component con) {
            try {
                  Robot r = new Robot();
                  Rectangle rect = new Rectangle(con.getLocationOnScreen().x, con.getLocationOnScreen().y, con.getWidth(), con.getHeight());
                  //BufferedImage image = r.createScreenCapture(rect);
                  BufferedImage image = (BufferedImage) con.createImage(con.getWidth(), con.getHeight());
                  int i = 1;
                  File f = new File(filename + i + ".jpg");                  
                  while (f.exists()) {
                        f = new File(filename + i + ".jpg");
                  ImageIO.write(image, "jpg", f);
            catch (AWTException e1) {}
            catch (IOException e2) {}

EDIT: changed the naming a little

Offline leknor

Junior Devvie


« Reply #1 - Posted 2003-04-29 19:21:50 »

How would overlapping windows effect your code?

I haven't done it but wouldn't the following psudo code be less error prone?

Image image = createImage(con.getWidth(), con.getHeight());
// Then your file output code to create the jpg.

Offline mill

Junior Devvie

popcorn freak

« Reply #2 - Posted 2003-04-29 20:51:01 »

it grabs whatever is visible in the speciefied area

in fullscreen this isn't a problem, but in windowed mode it certainly is if something is in front.

since i bound it to F12, the window would always be on top since it has to have focus in order to accept the key press in the first place.

some window managers don't necessary put the focused window on top so yes it migth be a problem Smiley

i tried what you suggested, but all it gave me was a white image.  any ideas?

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline leknor

Junior Devvie


« Reply #3 - Posted 2003-04-29 21:02:29 »

some window managers don't necessary put the focused window on top so yes it migth be a problem Smiley
I'm one of those "sloppy" focus kinda guys where the focus follows the mouse even if the window is obscured.

i tried what you suggested, but all it gave me was a white image.  any ideas?
Nope, it seems like a straight forward way to take a screen shot but I haven't put anymore thought into it beyond this thread.

I could have sworn that the custom Graphics hack is how people were getting getting swing to work in an OpenGL game. Oh well.

UPDATE: I guess you could look at the source for the paint method to see what's up if one really cared.
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

KaiHH (24 views)
2015-07-07 11:39:58

deepthought (55 views)
2015-06-30 15:39:44

deepthought (58 views)
2015-06-30 15:39:09

deepthought (67 views)
2015-06-30 15:36:52

Za\'Anzabar (45 views)
2015-06-29 05:44:54

TritonDreyja (51 views)
2015-06-24 17:10:40

CopyableCougar4 (53 views)
2015-06-23 00:34:45

BurntPizza (58 views)
2015-06-21 20:36:46

cookiecompiler (100 views)
2015-06-11 15:42:53

cookiecompiler (58 views)
2015-06-11 15:41:14
How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

Resources for WIP games
by kpars
2014-12-18 10:26:14 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‑
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!