How to take a screenshot in Java without AWT / Robot (entire screen) - java

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

Related

Libgdx with Java Swing issue

I have a problem with libgdx. I want to use Screen from libgdx to draw game inside JPanel (from Swing, because my all app is written in Swing). I've tried, but I cannot do that.
Is it possible? Have you got any code examples?
Please for help and sorry for my english (just in case).
Here is a good solution:
https://stackoverflow.com/a/21258666
It uses LWJGLCanvas to embed libGDx inside a JPanel

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

Screen Capture of DirectX programs with 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.

Drawing outside a window in Java?

Is it possible to simply paint() (or use some other function) to the screen in Java? As in draw over everything else on some coordinates of the screen itself, not inside some window.
If not, is it possible to make an invisible window that takes up the entire screen and use its glass pane to do it? Would complications arise from doing this? (Such as not being able to click on other applications)
Are there any other ways?
Thanks.
Edit: I'm not trying to do full screen with this, by the way.
When you paint() in Java, you're painting only within the confines of the size and location of what is being paint()ed.
If you're looking to do full screen stuff, there are tutorials for that:
http://download.oracle.com/javase/tutorial/extra/fullscreen/index.html
In theory, you can create an transparent undecorated maximized JFrame. This will allow you to "paint" over the desktop. Problems are obvious: if an application stays behind this window, it will not receive any mouse events.
Months ago, I made an evil cheat to draw directly on Windows Explorer's Desktop: mixing some .NET coding with JNI and Sun's internal classes - that's surreal, but works.

Flicker free AWT application

I'm trying to write a silly little app using Java and AWT.
It simply runs and animates some shapes, so as a first step, I created a simple app that clears a canvas with fillRect every 50ms.
The problem is, my app flickers every now and then with the underlying window colour. Google is failing me when it comes to finding simple hello-world type examples of flicker-free animating AWT apps.
What would the skeletal code for something like this look like?
Have a look for double buffering code.
http://www.codeproject.com/KB/graphics/javadoublebuffer.aspx

Categories

Resources