Java robot class capturing black/blank desktop images - Help

Posted on 2007-03-25
Medium Priority
Last Modified: 2013-12-29
I am currently capturing various images from the desktop using the robot class. Yet every now and again my program will take a completely black image, which renders my program useless. Does anyone have any suggestion why this is happening ? and what I can do prevent or fix it ?

At the moment I just restart my computer and it seems fine, but I don't want this to happen on my clients computer.

Question by:mr_mooray
LVL 86

Expert Comment

ID: 18787711
How are you running the Robot?

Author Comment

ID: 18787773
     try {
                  Robot robot = new Robot();

                  //capture a screenshot of desktop size
                  Rectangle captureSize = new Rectangle(Toolkit.getDefaultToolkit()
                  BufferedImage capture = robot.createScreenCapture(captureSize);

                  //save to file
                  ImageIO.write(capture, "bmp", new File("C:/Desktop.bmp"));

                  //Set Desktop Image
                  desktopImage = capture;

            } catch (HeadlessException e) {
                  // TODO Auto-generated catch block
            } catch (AWTException e) {
                  // TODO Auto-generated catch block
            } catch (IOException e) {
                  // TODO Auto-generated catch block
LVL 35

Expert Comment

ID: 18787868
The screensaver hasn't kicked in has it?
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.


Author Comment

ID: 18787881
No all screen savers are disabled, it just returns a completely black image. I don't think its my code, do you think it could be a different program interfering ?
LVL 30

Accepted Solution

Mayank S earned 1000 total points
ID: 18788981
http://forum.java.sun.com/thread.jspa?threadID=465261&messageID=2142224 says createScreenCapture () is slow - try JNI.

Assisted Solution

stimpyjcat earned 1000 total points
ID: 19397447

There are some instances where the robot (at least in its current implementation) is not capable of capturing the screen contents.   Some transparent windows, video, or other direct-to-hardware rendering may not be available for capture by the robot.  The capture will also be blank on w32 systems when effectively run as a service as the System user without desktop access.

If the capture is intermittently getting invalid results, then there's likely a bug in the capture.  One workaround would be to sample a few pixels to ensure the capture is not blank, re-capturing if the capture appears to have failed.

LVL 36

Expert Comment

ID: 19675493
This question has been classified as abandoned.  I will make a recommendation to the moderators on its resolution in approximately four days.  I would appreciate any comments by the experts that would help me in making a recommendation.

It is assumed that any participant not responding to this request is no longer interested in its final disposition.

If the asker does not know how to close the question, the options are here:

EE Cleanup Volunteer

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
This article will show, step by step, how to integrate R code into a R Sweave document
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question