0

Goal: A program that simulates the blurring effect that the top of a Windows frame has.

What I've so far:

http://imgur.com/cnkchZo

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:

http://imgur.com/zc5yF7q

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();
        }
    }
}
Community
  • 1
  • 1
  • Why are you trying to replicate an effect that's readily available to your application? – IInspectable Jun 26 '15 at 20:04
  • Java offers you access to OS via JNI, if that is what you really need. https://www3.ntu.edu.sg/home/ehchua/programming/java/JavaNativeInterface.html – John Jun 26 '15 at 20:05
  • @IInspectable , I figured it would be an interesting effect in undercoated JFrames. :) – John Smith Jun 26 '15 at 20:05
  • Using [DwmExtenFrameIntoClientArea](https://msdn.microsoft.com/en-us/library/windows/desktop/aa969512.aspx) may well be an option to achieve what you want. Without re-inventing it. – IInspectable Jun 26 '15 at 20:08
  • @user3360241 is it even possible to do what I'm asking in C/C++? – John Smith Jun 26 '15 at 20:08
  • If it is in WinApi it is possible. – John Jun 26 '15 at 20:10
  • @IInspectable , may you please link me to or provide for me an example, for I'm new to C++ and implementing it into java. – John Smith Jun 26 '15 at 20:19
  • @user3360241 , may you please link me to an example? – John Smith Jun 26 '15 at 20:51
  • @JohnSmith sorry i don't have link to specific part of windows API or C implementation which might help you. My understanding was that you already identified what might help you in the API ? If you are new to C++, you might wanna look for another solution, as both JNI and C++ are fairly difficult to use. Sadly i cannot help you with this problem within Java either – John Jun 26 '15 at 20:53
  • @user3360241 , don't worry about it. I'll learn how to use JNI. However, if you are apt in WinApi/C/C++, might you tell me if these are the functions I'm looking for: [DwmExtendFrameIntoClientArea function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa969512(v=vs.85).aspx) and [DwmEnableBlurBehindWindow function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa969508(v=vs.85).aspx)? – John Smith Jun 26 '15 at 21:01
  • These look exactly like what you need. – John Jun 26 '15 at 21:08
  • @user3360241 Thank you, cheers! – John Smith Jun 26 '15 at 21:14
  • @IInspectable , Thank you for linking me the functions! Cheers! – John Smith Jun 26 '15 at 21:15

0 Answers0