本文整理汇总了Java中javafx.scene.SnapshotParameters.setFill方法的典型用法代码示例。如果您正苦于以下问题:Java SnapshotParameters.setFill方法的具体用法?Java SnapshotParameters.setFill怎么用?Java SnapshotParameters.setFill使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javafx.scene.SnapshotParameters
的用法示例。
在下文中一共展示了SnapshotParameters.setFill方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: drawSprite
import javafx.scene.SnapshotParameters; //导入方法依赖的package包/类
/**
* Kirajzol egy TrainPartot a GraphicsContextre, elforgatva a sebessege iranyaba.
*/
private void drawSprite(TrainPart trainPart, Image sprite) {
ImageView iv = new ImageView(sprite);
Coordinate dir = trainPart.getDirection();
// Az elforgatas szoget az (1,0) vektorhoz viszonyitjuk, mert vizszintesen es jobbra allva taroljuk a spriteokat
Coordinate ref = new Coordinate(1, 0);
double deg = Math.toDegrees(Math.acos(Coordinate.dot(dir, ref)));
// Ha az elforgatas szoge > 180 fok, akkor is jo iranyba forgassuk
if (Coordinate.cross(dir, ref) > 0) {
deg = 360 - deg;
}
iv.setRotate(deg);
SnapshotParameters param = new SnapshotParameters();
param.setFill(Color.TRANSPARENT);
Image rotatedImage = iv.snapshot(param, null);
graphicsContext.drawImage(rotatedImage, trainPart.getPos().getX() - rotatedImage.getWidth() / 2, trainPart.getPos().getY() - rotatedImage.getHeight() / 2);
}
示例2: updatePlaceholder
import javafx.scene.SnapshotParameters; //导入方法依赖的package包/类
private void updatePlaceholder(Node newView) {
if (view.getWidth() > 0 && view.getHeight() > 0) {
SnapshotParameters parameters = new SnapshotParameters();
parameters.setFill(Color.TRANSPARENT);
Image placeholderImage = view.snapshot(parameters,
new WritableImage((int) view.getWidth(), (int) view.getHeight()));
placeholder.setImage(placeholderImage);
placeholder.setFitWidth(placeholderImage.getWidth());
placeholder.setFitHeight(placeholderImage.getHeight());
} else {
placeholder.setImage(null);
}
placeholder.setVisible(true);
placeholder.setOpacity(1.0);
view.getChildren().setAll(placeholder, newView);
placeholder.toFront();
}
示例3: node2Png
import javafx.scene.SnapshotParameters; //导入方法依赖的package包/类
/**
* 把一个Node导出为png图片
*
* @param node 节点
* @param saveFile 图片文件
* @param width 宽
* @param height 高
* @return 是否导出成功
*/
public static boolean node2Png(Node node, File saveFile, double width, double height) {
SnapshotParameters parameters = new SnapshotParameters();
// 背景透明
parameters.setFill(Color.TRANSPARENT);
WritableImage image = node.snapshot(parameters, null);
// 重置图片大小
ImageView imageView = new ImageView(image);
imageView.setFitWidth(width);
imageView.setFitHeight(height);
WritableImage exportImage = imageView.snapshot(parameters, null);
try {
return ImageIO.write(SwingFXUtils.fromFXImage(exportImage, null), "png", saveFile);
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
示例4: createImage
import javafx.scene.SnapshotParameters; //导入方法依赖的package包/类
/**
* Adapted from http://wecode4fun.blogspot.co.uk/2015/07/particles.html (Roland C.)
*
* Snapshot an image out of a node, consider transparency.
*/
private static Image createImage(Node node) {
SnapshotParameters parameters = new SnapshotParameters();
parameters.setFill(Color.TRANSPARENT);
int imageWidth = (int) node.getBoundsInLocal().getWidth();
int imageHeight = (int) node.getBoundsInLocal().getHeight();
WritableImage image = new WritableImage(imageWidth, imageHeight);
Async.startFX(() -> {
node.snapshot(parameters, image);
}).await();
return image;
}
示例5: generate
import javafx.scene.SnapshotParameters; //导入方法依赖的package包/类
/**
* Converts an unicode char to an Image using the FontAwesome font.
* <p/>
* <p>
* Based on the code presented here: <a href=
* "http://news.kynosarges.org/2014/01/07/javafx-text-icons-as-images-files/">
* javafx-text-icons-as-images-files </a>
* </p>
*
* @param unicode
* The String with the unicode which will be turned into an image.
* @param color
* The color of the font.
* @param size
* The size of the image.
* @return An Image with the unicode char converted to an image.
*/
public static Image generate(String unicode, Paint color, int size) {
Font newFont;
if (size == SIZE) {
newFont = FONT;
} else {
InputStream fontIS = FontAwesomeImageCreator.class.getResourceAsStream("/fonts/fontawesome-webfont.ttf");
newFont = Font.loadFont(fontIS, size);
}
final Canvas canvas = new Canvas(size, size);
final GraphicsContext gc = canvas.getGraphicsContext2D();
gc.setFill(color);
gc.setFont(newFont);
gc.setTextAlign(TextAlignment.CENTER);
gc.setTextBaseline(VPos.CENTER);
gc.fillText(unicode, size / 2, size / 2);
final SnapshotParameters params = new SnapshotParameters();
params.setFill(Color.TRANSPARENT);
return canvas.snapshot(params, null);
}
示例6: saveAllDigits
import javafx.scene.SnapshotParameters; //导入方法依赖的package包/类
public static void saveAllDigits() {
Stage stage = new Stage(StageStyle.TRANSPARENT);
DigitTemplate root = new DigitTemplate();
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
SnapshotParameters snapshotParams = new SnapshotParameters();
snapshotParams.setFill(Color.TRANSPARENT);
root.digit.setText("-");
for (int i = 0; i <= 10; i++) {
WritableImage image = root.digit.snapshot(snapshotParams, null);
File file = new File("src/" + IconFactory.RESOURCE_PATH + "/img/common/digits/" + root.digit.getText() + ".png");
try {
ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", file);
} catch (IOException e) {
e.printStackTrace();
}
root.digit.setText("" + i);
}
stage.close();
}
示例7: createPopupItem
import javafx.scene.SnapshotParameters; //导入方法依赖的package包/类
private Node createPopupItem(final GalleryItem item)
{
SnapshotParameters snapshotParameters = new SnapshotParameters();
snapshotParameters.setFill(Color.TRANSPARENT);
Image image = item.getGraphic().snapshot(snapshotParameters, null);
ToggleButton button = new ToggleButton(item.getName());
button.setContentDisplay(ContentDisplay.TOP);
button.setGraphic(new ImageView(image));
button.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
gallery.setSelectedItem(item);
}
});
buttonGroup.getToggles().add(button);
galleryItemButton.put(item, button);
return button;
}
示例8: storeSnapshot
import javafx.scene.SnapshotParameters; //导入方法依赖的package包/类
/**
* ノードの内容をPNGファイルとして出力します
*
* @param ndoe ノード
* @param title タイトル及びファイル名
* @param own 親ウインドウ
*/
public static void storeSnapshot(Node node, String title, Window own) {
try {
FileChooser chooser = new FileChooser();
chooser.setTitle(title + "の保存");
chooser.setInitialFileName(title + ".png");
chooser.getExtensionFilters().addAll(
new ExtensionFilter("PNG Files", "*.png"));
File f = chooser.showSaveDialog(own);
if (f != null) {
SnapshotParameters sp = new SnapshotParameters();
sp.setFill(Color.WHITESMOKE);
WritableImage image = node.snapshot(sp, null);
try (OutputStream out = Files.newOutputStream(f.toPath())) {
ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", out);
}
}
} catch (Exception e) {
alert(AlertType.WARNING, "画像ファイルに保存出来ませんでした", "指定された場所へ画像ファイルを書き込みできませんでした", e, own);
}
}
示例9: justResize
import javafx.scene.SnapshotParameters; //导入方法依赖的package包/类
public static Image justResize(Canvas canvas) {
SnapshotParameters params = new SnapshotParameters();
params.setFill(Color.TRANSPARENT);
PixelReader reader = canvas.snapshot(params, null).getPixelReader();
double canvasWidth = canvas.getWidth();
double canvasHeight = canvas.getHeight();
int startX = getStartX(reader, canvasWidth, canvasHeight);
int startY = getStartY(reader, canvasWidth, canvasHeight);
int endX = getEndX(reader, canvasWidth, canvasHeight);
int endY = getEndY(reader, canvasWidth, canvasHeight);
//何も描かれていないキャンバス
if (startX == 0 && startY == 0 && endX == 0 && endY == 0) {
return null;
}
return new WritableImage(reader, startX, startY, endX - startX, endY - startY);
}
示例10: onCopyClicked
import javafx.scene.SnapshotParameters; //导入方法依赖的package包/类
@FXML
public void onCopyClicked() {
WritableImage wim = new WritableImage(canvasWidth, canvasHeight);
SnapshotParameters params = new SnapshotParameters();
params.setFill(Color.TRANSPARENT);
canvas.snapshot(params, wim);
copyImageToClipboard(wim);
}
示例11: toWritableImage
import javafx.scene.SnapshotParameters; //导入方法依赖的package包/类
@Override
public WritableImage toWritableImage(Rectangle2D viewport)
{
SnapshotParameters params = new SnapshotParameters();
params.setViewport(viewport);
params.setFill(Color.TRANSPARENT);
return this.snapshot(params, null);
}
示例12: SnapshotWithParametersTest_fill
import javafx.scene.SnapshotParameters; //导入方法依赖的package包/类
/**
* test Node.snapshot with SnapshotParameters
*/
@Test
public void SnapshotWithParametersTest_fill() throws InterruptedException {
SnapshotParameters param = new SnapshotParameters();
param.setFill(new LinearGradient(0, 0, 1, 2, true, CycleMethod.REPEAT, new Stop[]{new Stop(0, Color.AQUA), new Stop(0.5f, Color.RED)}));
testCommon(Pages.DropShadow.name(),"fill", param);
}
示例13: buildImage
import javafx.scene.SnapshotParameters; //导入方法依赖的package包/类
public static Image buildImage(IconCode iconCode, Number size, Paint fill, Paint stroke) {
IconNode iconNode = new IconNode();
iconNode.setIconCode(iconCode);
iconNode.setIconSize(size);
iconNode.setFill(fill);
iconNode.setStroke(stroke);
Group group = new Group(iconNode);
new Scene(group);
SnapshotParameters parameters = new SnapshotParameters();
parameters.setFill(Color.TRANSPARENT);
return group.snapshot(parameters, null);
}
示例14: createDragImage
import javafx.scene.SnapshotParameters; //导入方法依赖的package包/类
protected static Image createDragImage(FxDockPane client)
{
SnapshotParameters sp = new SnapshotParameters();
sp.setFill(Color.TRANSPARENT);
WritableImage im = client.snapshot(sp, null);
if(client.isPaneMode())
{
return im;
}
// include selected tab
FxDockTabPane tp = (FxDockTabPane)DockTools.getParent(client);
Node n = tp.lookup(".tab:selected");
WritableImage tim = n.snapshot(sp, null);
double dy = tim.getHeight();
// must adjust for the tab
deltay += dy;
double w = Math.max(im.getWidth(), tim.getWidth());
double h = im.getHeight() + dy;
Canvas c = new Canvas(w, h);
GraphicsContext g = c.getGraphicsContext2D();
g.drawImage(tim, 0, 0);
g.drawImage(im, 0, dy);
return c.snapshot(sp, null);
}
示例15: getBackgroundLoading
import javafx.scene.SnapshotParameters; //导入方法依赖的package包/类
/**
* キャラクターの画像を取得します(装飾無し、バックグラウンドでのロード)
*
* @param chara キャラクター
* @return 艦娘の画像
* @throws IllegalStateException このメソッドがJavaFXアプリケーション・スレッド以外のスレッドで呼び出された場合
*/
public static Image getBackgroundLoading(Chara chara) throws IllegalStateException {
Image img = ShipImage.getBackgroundLoading(chara);
if (img != null) {
return img;
}
Canvas canvas = new Canvas(160, 40);
SnapshotParameters sp = new SnapshotParameters();
sp.setFill(Color.TRANSPARENT);
return canvas.snapshot(sp, null);
}