Goal: A program that simulates the blurring effect that the top of a Windows frame has.
What I've so far:
The frame's opacity is set to 95%, so the frame is slightly translucent. The program takes a screenshot of whatever is inside the frame, blurs it, and sets the blurred image as the background for the frame. The problem is that the frame is translucent, so Windows still paints the desktop underneath, causing not a complete blur for my program.
I've tried setting the frame invisible (in another case: setting the opacity to 0.0f), taking the screenshot, blurring it, setting it as the background of the frame, and repeating continuously for the desired effect, but the screen either lags or appears to "flash", making it unbearable to watch.
I'm looking to achieve this:
Through research on here, I've learned that taking a screenshot of behind an active window is not possible in Java without tight native integration with the window-manager of the platform in question, according to Java- screen capture behind the application.
I've also discovered that Windows API might be able to help. How would I be able to accomplish this goal with using Java or WinApi via JNA or something similar to it? re: Is there a Java library to access the native Windows API?
This is my current code:
public class BlurThread extends Thread {
private final JFrame j;
private final int BLUR_FACTOR = 10;
private Robot r;
public BlurThread(JFrame j) {
this.j = j;
}
@Override
public void run() {
try {
r = new Robot();
BufferedImage nullImage = null, screenShot, filter;
BufferedImageOp a = new GaussianFilter(BLUR_FACTOR);
while (true) {
screenShot = r.createScreenCapture(new Rectangle(j.getX(), j.getY(), j.getWidth(), j.getHeight()));
filter = a.filter(screenShot, nullImage);
ImageIcon i = new ImageIcon(filter);
Mover.setIcon(i); // JLabel
}
} catch (AWTException ex) {
ex.printStackTrace();
}
}
}