下面列出了javafx.scene.Scene#snapshot ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void takeSnapshot(final Scene scene) {
// Take snapshot of the scene
final WritableImage writableImage = scene.snapshot(null);
// Write snapshot to file system as a .png image
final File outFile = new File("snapshot/radialmenu-snapshot-"
+ snapshotCounter + ".png");
outFile.getParentFile().mkdirs();
try {
ImageIO.write(SwingFXUtils.fromFXImage(writableImage, null), "png",
outFile);
} catch (final IOException ex) {
System.out.println(ex.getMessage());
}
snapshotCounter++;
}
private void takeSnapshot(final Scene scene) {
// Take snapshot of the scene
final WritableImage writableImage = scene.snapshot(null);
// Write snapshot to file system as a .png image
final File outFile = new File("snapshot/radialmenu-snapshot-"
+ snapshotCounter + ".png");
outFile.getParentFile().mkdirs();
try {
ImageIO.write(SwingFXUtils.fromFXImage(writableImage, null), "png",
outFile);
} catch (final IOException ex) {
System.out.println(ex.getMessage());
}
snapshotCounter++;
}
private void takeSnapshot(final Scene scene) {
// Take snapshot of the scene
final WritableImage writableImage = scene.snapshot(null);
// Write snapshot to file system as a .png image
final File outFile = new File("snapshot/radialmenu-snapshot-"
+ snapshotCounter + ".png");
outFile.getParentFile().mkdirs();
try {
ImageIO.write(SwingFXUtils.fromFXImage(writableImage, null), "png",
outFile);
} catch (final IOException ex) {
System.out.println(ex.getMessage());
}
snapshotCounter++;
}
private void takeSnapshot(final Scene scene) {
// Take snapshot of the scene
final WritableImage writableImage = scene.snapshot(null);
// Write snapshot to file system as a .png image
final File outFile = new File("snapshot/radialmenu-snapshot-"
+ snapshotCounter + ".png");
outFile.getParentFile().mkdirs();
try {
ImageIO.write(SwingFXUtils.fromFXImage(writableImage, null), "png",
outFile);
} catch (final IOException ex) {
System.out.println(ex.getMessage());
}
snapshotCounter++;
}
private void takeSnapshot(final Scene scene) {
// Take snapshot of the scene
final WritableImage writableImage = scene.snapshot(null);
// Write snapshot to file system as a .png image
final File outFile = new File("snapshot/"+getClass().getSimpleName().toLowerCase()+"-"
+ snapshotCounter + ".png");
outFile.getParentFile().mkdirs();
try {
ImageIO.write(SwingFXUtils.fromFXImage(writableImage, null), "png",
outFile);
} catch (final IOException ex) {
System.out.println(ex.getMessage());
}
snapshotCounter++;
}
private void takeSnapshot(final Scene scene) {
// Take snapshot of the scene
final WritableImage writableImage = scene.snapshot(null);
// Write snapshot to file system as a .png image
final File outFile = new File("snapshot/radialmenu-snapshot-"
+ snapshotCounter + ".png");
outFile.getParentFile().mkdirs();
try {
ImageIO.write(SwingFXUtils.fromFXImage(writableImage, null), "png",
outFile);
} catch (final IOException ex) {
System.out.println(ex.getMessage());
}
snapshotCounter++;
}
public void takeSnapShot(OutputStream output)
{
JavaFxRunnable worker = new JavaFxRunnable()
{
public void myWork()
throws Exception
{
Scene scene = console.getConsoleScene();
WritableImage writableImage =
new WritableImage((int)scene.getWidth(), (int)scene.getHeight());
scene.snapshot(writableImage);
try
{
ImageIO.write(SwingFXUtils.fromFXImage(writableImage, null), "png", output);
}
catch (IOException ex)
{
log.error( "Snapshot failed with: ", ex );
}
}
};
Platform.runLater( worker );
worker.doWait();
}
private void saveScreenshot(Scene scene) {
WritableImage fxImage = scene.snapshot(null);
BufferedImage awtImage = SwingFXUtils.fromFXImage(fxImage, null);
try {
ImageIO.write(awtImage, "png", new File("screenshot.png"));
} catch (IOException e) {
e.printStackTrace();
}
}
private void createBackgroundTextures() {
final int tileSize = 600;
// TODO: remove this duplication
Group backgroundGroup = new Group();
Scene offScreenBackgroundScene = new Scene(backgroundGroup, tileSize, tileSize);
Shape emptySpace = new Rectangle(0, 0, tileSize, tileSize);
emptySpace.setFill(EnvironmentView.BACKGROUND_COLOR);
backgroundGroup.getChildren().add(emptySpace);
Group infraredBackgroundGroup = new Group();
Scene offScreenInfraredBackgroundScene = new Scene(infraredBackgroundGroup, tileSize, tileSize);
Shape infraredEmptySpace = new Rectangle(0, 0, tileSize, tileSize);
infraredEmptySpace.setFill(EnvironmentView.INFRARED_BACKGROUND_COLOR);
infraredBackgroundGroup.getChildren().add(infraredEmptySpace);
for (int i = 0; i < 5; i++) {
int x = getRandomCoordinate(tileSize);
int y = getRandomCoordinate(tileSize);
backgroundGroup.getChildren().add(createSpeckle(x, y, NORMAL_SPECKLE_RADIUS));
infraredBackgroundGroup.getChildren().add(createSpeckle(x, y, INFRARED_SPECKLE_RADIUS));
}
backgroundTexture = new WritableImage(tileSize, tileSize);
offScreenBackgroundScene.snapshot(backgroundTexture);
infraredBackgroundTexture = new WritableImage(tileSize, tileSize);
offScreenInfraredBackgroundScene.snapshot(infraredBackgroundTexture);
}