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


Java Canvas.getWidth方法代碼示例

本文整理匯總了Java中javafx.scene.canvas.Canvas.getWidth方法的典型用法代碼示例。如果您正苦於以下問題:Java Canvas.getWidth方法的具體用法?Java Canvas.getWidth怎麽用?Java Canvas.getWidth使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javafx.scene.canvas.Canvas的用法示例。


在下文中一共展示了Canvas.getWidth方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: getTopLeftCorner

import javafx.scene.canvas.Canvas; //導入方法依賴的package包/類
public static DrawCoords getTopLeftCorner(Canvas canvas) {
	double length = getBoardLength(canvas);
	double canvasWidth = canvas.getWidth();
	double canvasHeight = canvas.getHeight();

	double x = 0;
	double y = 0;

	if ( canvasWidth > length )
		x = (canvasWidth - length) / 2;
	else
		y = (canvasHeight - length) / 2;

	return new DrawCoords(x, y);
}
 
開發者ID:GoSuji,項目名稱:Suji,代碼行數:16,代碼來源:DimensionHelper.java

示例3: getBoardLength

import javafx.scene.canvas.Canvas; //導入方法依賴的package包/類
public static double getBoardLength(Canvas canvas) {
	double canvasWidth = canvas.getWidth();
	double canvasHeight = canvas.getHeight();

	return Math.min(canvasHeight, canvasWidth);
}
 
開發者ID:GoSuji,項目名稱:Suji,代碼行數:7,代碼來源:DimensionHelper.java

示例4: drawStrokes

import javafx.scene.canvas.Canvas; //導入方法依賴的package包/類
/**
 * Draws out the all of the phonemes in stroke form on the canvas of the Application.
 *
 * @param s The string that is to be split up and put into phonemes, and then drawn out.
 */
private void drawStrokes(String s, GraphicsContext gc){

    Canvas canvas = gc.getCanvas();

    // Clears all of the previous drawings
    gc.clearRect(0,0, canvas.getWidth(), canvas.getHeight());


    Character[][] phones = TextProc.phones(s);
    int x = 90;
    int y = 100;
    int line = 1;
    Stroke current;

    //Iterates through the sentence
    for (Character[] word : phones) {

        // Checks to see if it is necessary to wrap at the word. The on the end is for padding
        if((canvas.getWidth() - 90)  - x < GraphicsCalculations.wordLength(word)){
            line++;
            x = 80;
            y = line * 80;
        }

        y -= GraphicsCalculations.wordHeight(word);
        // Iterates through the word
        for (Character c : word) {

            // Don't bother with the vowels yet, only draw outlines.
            if (TextProc.isVowel(c)){
                continue;
            }

            current = TextProc.strokeMap.get(c);

            // The starting and ending points of the current stroke
            Point start = current.getStart();
            Point end = current.getEnd();

            // Draw the image
            gc.drawImage(current.getImage(), x - start.x, y - start.y);

            // Moves the pointer to the end of the stroke
            x += end.x - start.x;
            y += end.y - start.y;

        }

        // Puts 80 pixels in between words to fo indicate a space until joining is funtioning
        x += 80;
        y = line * 100;
    }

}
 
開發者ID:squablyScientist,項目名稱:Pitman-Translator,代碼行數:60,代碼來源:Scratchpad.java


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