要擴大Jewlsea的回答。而使用JavaFX的只有上面的例子..
雖然類不是公共API,它避免了AWT棧完全。 這裏是一個非公開例如:添加
// copy a background node to be frozen over.
private Image copyBackground(Stage stage) {
final int X = (int) stage.getX();
final int Y = (int) stage.getY();
final int W = (int) stage.getWidth();
final int H = (int) stage.getHeight();
final Screen screen = Screen.getPrimary();
try {
Robot rbt = com.sun.glass.ui.Application.GetApplication().createRobot();
Pixels p = rbt.getScreenCapture(
(int)screen.getBounds().getMinX(),
(int)screen.getBounds().getMinY(),
(int)screen.getBounds().getWidth(),
(int)screen.getBounds().getHeight(),
true
);
WritableImage dskTop = new WritableImage((int)screen.getBounds().getWidth(), (int)screen.getBounds().getHeight());
dskTop.getPixelWriter().setPixels(
(int)screen.getBounds().getMinX(),
(int)screen.getBounds().getMinY(),
(int)screen.getBounds().getWidth(),
(int)screen.getBounds().getHeight(),
PixelFormat.getByteBgraPreInstance(),
p.asByteBuffer(),
(int)(screen.getBounds().getWidth() * 4)
);
WritableImage image = new WritableImage(W,H);
image.getPixelWriter().setPixels(0, 0, W, H, dskTop.getPixelReader(), X, Y);
return image;
} catch (Exception e) {
System.out.println("The robot of doom strikes!");
e.printStackTrace();
return null;
}
}
結果與一個小陰影效果:
DropShadow shdw = new DropShadow();
shdw.setBlurType(BlurType.GAUSSIAN);
shdw.setColor(Color.GAINSBORO);
shdw.setRadius(10);
shdw.setSpread(0.12);
shdw.setHeight(10);
shdw.setWidth(10);
layout.setEffect(shdw);
![fxScreenCapture](https://i.stack.imgur.com/8xQTs.png)
大聲笑。你再做一次:D。在賞金結束之前幾秒鐘,我給了你一件好事。我在那裏嚇壞了。 – Taconut
嘿!我做到了,所以你可以在FrostyPane上加載任何節點,並在窗口沒有焦點時關閉模糊(使其始終保持一致)。我有幾個問題:1.我刪除了暫停50ms一切的代碼,它仍然正常工作。有什麼我失蹤? 2.拖動窗口重新啓動我正在進行的任何功能。例如,當我移動窗口時,我的啓動畫面會重新啓動。任何方式在這個?另外,有什麼方法可以輕鬆實現調整大小?我想我可以處理它,但我只想知道你是否知道任何捷徑。 – Taconut
不幸的是,如果背景變化,玻璃效果將不會重繪。否則,看起來不錯。 – dejuknow