本文整理汇总了Java中javafx.scene.canvas.Canvas.snapshot方法的典型用法代码示例。如果您正苦于以下问题:Java Canvas.snapshot方法的具体用法?Java Canvas.snapshot怎么用?Java Canvas.snapshot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javafx.scene.canvas.Canvas
的用法示例。
在下文中一共展示了Canvas.snapshot方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: take
import javafx.scene.canvas.Canvas; //导入方法依赖的package包/类
/**
* Takes a snapshot of a canvas and saves it to the destination.
* <p>
* After the screenshot is taken it shows a dialogue to the user indicating the location of the snapshot.
*
* @param canvas a JavaFX {@link Canvas} object
* @return the destination of the screenshot
*/
public String take(final Canvas canvas) {
final WritableImage writableImage = new WritableImage((int) canvas.getWidth(), (int) canvas.getHeight());
final WritableImage snapshot = canvas.snapshot(new SnapshotParameters(), writableImage);
try {
ImageIO.write(SwingFXUtils.fromFXImage(snapshot, null), FILE_FORMAT, destination);
new InformationDialogue(
"Snapshot taken",
"You can find your snapshot here: " + destination.getAbsolutePath()
).show();
} catch (final IOException e) {
LOGGER.error("Snapshot could not be taken.", e);
new ErrorDialogue(e).show();
}
return destination.getAbsolutePath();
}
示例2: getScaledImage
import javafx.scene.canvas.Canvas; //导入方法依赖的package包/类
private BufferedImage getScaledImage(Canvas canvas) {
// for a better recognition we should improve this part of how we retrieve the image from the canvas
WritableImage writableImage = new WritableImage(CANVAS_WIDTH, CANVAS_HEIGHT);
canvas.snapshot(null, writableImage);
Image tmp = SwingFXUtils.fromFXImage(writableImage, null).getScaledInstance(28, 28, Image.SCALE_SMOOTH);
BufferedImage scaledImg = new BufferedImage(28, 28, BufferedImage.TYPE_BYTE_GRAY);
Graphics graphics = scaledImg.getGraphics();
graphics.drawImage(tmp, 0, 0, null);
graphics.dispose();
return scaledImg;
}