How to get a sharp image of a node

2019-08-26 01:33发布

I use the following code to generate an image of a node and add it with an ImageView to my Scene:

SnapshotParameters snapParams = new SnapshotParameters();
snapParams.setFill(Color.TRANSPARENT);
this.dragImage = new ImageView(draggable.snapshot(snapParams, null));

...

frontPane.getChildren().add(this.dragImage);
Bounds localBounds = frontPane.sceneToLocal(draggable
    .localToScene(draggable.getBoundsInLocal()));
this.dragImage.relocate(localBounds.getMinX(),
localBounds.getMinY());

Unfortunately, the rendered image is very blurred as can be seen in my screenshot. Any ideas what might be the problem or how to retreive an unblurred image would be welcome.

Update:

while playing arround i removed

this.dragImage.relocate(localBounds.getMinX(),localBounds.getMinY());

which results in a sharp image with no blur at all. I have no idea why this is the case and i still need to translate the image to the correct position.

blurred snapshot

标签: javafx-2
1条回答
小情绪 Triste *
2楼-- · 2019-08-26 01:59

I got rid of the blur with a simple cast to int in the relocate call:

this.dragImage.relocate((int) localBounds.getMinX(),(int) localBounds.getMinY());

I found that localBounds.getMinX() is 638.5 and localBounds.getMinY() is 136.5. Further experimentation brought me to the conclusion that non integral values for the translation led to the blurred image.

An explanation for this can be found in the API doc for Shape at "Interaction with coordinate systems".

查看更多
登录 后发表回答