本文整理汇总了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();
}
示例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);
}
示例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);
}
示例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;
}
}