How to get a sharp image of a node

旧时模样 提交于 2020-02-07 03:57:08

问题


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.


回答1:


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".



来源:https://stackoverflow.com/questions/13176060/how-to-get-a-sharp-image-of-a-node

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!