當前位置: 首頁>>代碼示例>>Java>>正文


Java Canvas.snapshot方法代碼示例

本文整理匯總了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();
}
 
開發者ID:ProgrammingLife2017,項目名稱:hygene,代碼行數:26,代碼來源:Snapshot.java

示例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;
}
 
開發者ID:jesuino,項目名稱:java-ml-projects,代碼行數:12,代碼來源:MnistTestFXApp.java


注:本文中的javafx.scene.canvas.Canvas.snapshot方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。