Screen Capture of DirectX programs with Java - java

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.

Related

Taking a screenshot in Java on Linux?

I want to be able to take a screenshot of a portion or all of the screen using Java. The generally accepted method of doing this to use the Robot class, but that doesn't work in this case. I have multiple transparent JavaFX stages on the screen, and any screenshot taken with the Robot class seems to treat them as completely opaque.
I have also tried having the program simulate the presses of Ctrl+PrtSc. I can't seem to get it to actually put the screenshot into the clipboard before the method finishes though, even if I attempt to have it wait until there is a picture in the clipboard.
Is there any more direct way of getting a screenshot? Anything specific to Swing/AWT, unfortunately, will not work.

Get Image from an Application

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.

Take screen shots inside of full screen applications with java?

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)...

How do you make such complex GUI in Java? Is it possible with Gwt? Or need to use something else?

My goal is to make a simple GUI which almost look like this attached screenshot.
But while using Awt, Swing i have never found yet such combo/buttons nor i have found something like transparent window which showing my desktop background.
I am very desperate to make something similar, but i am not sure which framework i can use?
Can i do this above UI, with GWT? or is there something else?
Java has always supported translucent windows on Mac (from at least OS X 10.4 but probably way before that too).
However on Windows you need at least Java 1.6.0_10 to be able to do translucent windows directly from Java.
If for whatever reason you're stuck with an older Java you can use JNA. They've got examples as to how to create translucent windows on OS X, Windows and Linux and these examples work even on older JVMs.
As I type this JNA is located here:
https://github.com/twall/jna
Here's the code for their alpha/translucent example (where you can drag a picture with an alpha channel, like a PNG with an alpha channel and then choose the opacity):
https://github.com/twall/jna/tree/master/contrib/alphamaskdemo/com/sun/jna/contrib/demo
Now what you want to do can be done but there are gotchas: you need to be careful about several things. For example mouse events: if you want catch them or not when they happen on an area that is "fully transparent" (if you want to catch them, you can cheat and make your translucent window nearly --but not fully-- transparent).
What you want to do is a bit like a HUD: there are definitely HUDs done in Java but as far as I know they weren't build using GUI builder tools. You'll probably have to code it manually (or at least some part of it manually).
See this: How to Create Translucent and Shaped Windows

Screen capture of a java applet

I'd like to "capture" a screenshot of what a java applet would currently look like if it were loaded, effectively screenshoting an applet without the use of a vdu.
The purpose of this is to display the image to a user that doesn't have a JVM. Lets assume the applet is a digital clock and has no requirement on user input. So what could be done is set up a pc connected to a vdu, open the applet, schedule a script to take a screenshot and upload the image. Clients could then access what the applet would look like at any given time without the requirement on a jvm.
It'd be such a hassle to have a pc running all the time etc. Surely this could be done somehow without a display.
Would it be possible to create a virtual display in a jvm that can render an applet and then take a screen capture?
If this were possible then perhaps a really high resolution display could be virtualized to create a very high resolution screenshot.
The ScreenImage class should handle this.
Look at java.awt.Robot#createScreenCapture(java.awt.Rectangle)
If this would work, i would wonder, remind the sandbox, and as the above link stated "This will work whether you have an AWT or Swing application."
If you use a "rendering-engine" (composing each pixel to something paintable before repaint()'ing) within you applet, you could use this information and create an image.

Categories

Resources