I'm using the standard method of taking screenshots using the Java Robot class, i.e.:
BufferedImage screencapture = robot.createScreenCapture(new Rectangle(tool.getScreenSize()));
This works fine most of the time, but it just takes pictures of a blank screen inside of full screen applications (I'm using Windows 7, so most of these are using Direct X for fullscreen). Is this a known problem for the Robot class or am I doing something wrong?
The Robot class cannot capture fullscreen DirectX or OpenGL applications.
I just did some quick Google'ing and found JavaCV. It will be a lot more involved than just using Robot, but JavaCV (mainly the OpenCV wrappers) should allow you to do this. (Don't quote me on it though)...
Related
I'm running Sikuli API from Java on a game we are running in the company on full screen. The problem is that Sikuli sees the layer beneath the game (the desktop) but not the game itself. It's like the game is transparent to Sikuli. I took a screenshot through RobotFW and also, the image I'm getting is the layer beneath. So this looks like a general issue and not specific to Sikuli.
What can I do?
The games are developed in Unity
What if you use a App.focus(<appName>) before executing your code?
By using App.focus() you pull that application to the foreground.
Sorry, this question is pretty broad, but I haven't a clue how to go about it.
In Java, how can I get whatever a Windows application is displaying in the form of an Image?
I'd like the contents of the Image to include just a frame from one application window, not a whole monitor.
I think getting the application window from the title of the window may be a start, but does Java even have access to the GUIs of other processes?
The best you can do in pure Java is to use the Robot class to capture a specified rectangle. The following Q&A show how ... for the case where the rectangle is the entire screen.
Screenshot capture in Window 8 OS
(This should work for all non-headless Java SE platforms.)
That's the easy bit. The hard bit is figuring out what rectangle to screenshot. The Java libraries provide no APIs for finding information about the screen locations of "other" applications. To find that kind of information, your Java application would need to interact with the native OS via a native library or an external utility command. This will inevitably be platform specific ... meaning that it will break for Mac and Linux, and possibly for other versions of Windows as well.
I wouldn't try to do this in Java at all. Instead, I would look for an OS-specific screenshot application that can be run as an external application; e.g. using Process.exec. Alternatively, I'd figure out how to write such an app, in (say) C#.
I think getting the application window from the title of the window may be a start, but does Java even have access to the GUIs of other processes?
Nope and nope.
I've seen the usual way of taking a screenshot in Java where you use a Robot and a BufferedImage to take a screenshot. But is there a way of doing this without using Robot and BufferedImage?
Why?
I am working with JavaFX and I don't like mixing up AWT (Swing) and JavaFX.
Not a big problem, I know, but I would love to keep everything within one library.
I've also heard that Robot is a bit slow, but that's not the main reason.
EDIT: I would like to capture the whole screen and not just an area like a scene.
Thanks in advance :D
I have a paint program written in java with SWT. I am testing with SWTBot. My test case is to draw a picture on the canvas, capture the image of the canvas, and compare to the expected image.
The problem is that I can't find any way to move the mouse using the SWTBot. Apparently it only allows me to click the mouse. I want to
move to an x,y location
mouse down
move to another x,y location
mouse up
Any advice?
I've decided to stop using SWTBot. The functionality is very weak. It is designed for Eclipse apps, so it doesn't really support plain SWT apps very well. Although having direct access to the widgets is somewhat appealing, the requirement of running the test code in the app process is awkward.
I've decided to use Sikuli instead. It has pretty good API for both Java and Python. It seems to have more function and better support than SWTBot.
I wrote a Java application that uses the java.awt.Robot to take screen captures of the screen and was wondering if capturing a program using DirectX/OpenGL would be possible?
Each time I try to do this, I get a black screen
Don't know if this is really a solution but seems there's more possible ways to get the screenshot information using a "FrameGrabber" or some related class from JavaCV possibly: http://code.google.com/p/javacv/
Some of the final output shown on the screen could be calculated on a graphics card that has shaders set to act on the image data before it gets put into a display buffer for what's shown so it's possible some effects would be impossible to capture without an analog loopback (go from video out to video in on a capture card).
Related post How to take screenshots fast in Java?
OpenGL is a drawing API, not an all purpose interface to the graphics system. There were times, when taking screenshots with OpenGL was indeed possible through some dirty hacks. However recently I tried to re-implement this on modern OS to see if it still works, and no, it doesn't anymore.
Yes it is possible. But maybe only in limited circiumstances.
I've successfully captured the contents on OpenGL (jogl) windows on linux and windows using the Robot createScreenCapture.
Some specific information about the implementation that may be different for you:
The call to createScreenCapture was done from within the OpenGL
application.
The application used heavyweight GLCanvas
It used Java 6
Make sure you pass it the correct coordinates. You can get the screen coordinates to use from the GraphicsEnvironment
Uhh... a hard one ;o)
I had a try with some other screenshot utils and got a black screen, too. Looks like DirectX is passing the graphics directly to the monitor output. I am wondering if that could be accessed within a java application.