2

I'm trying to create a image editor tool, where I have X- and Y-axis. Now I want to support the user by seeing each pixel when zooming in so that they can work more exactly. In comparison you should take a look at paint.net where you can see the pixels when zooming in. I'll give you a code snippet and perhaps you might have a hint for me where I should dig into (API or code examples). I've found nothing like it in the JAVAFX API documentation. I want to use an ImageView instance but not a Canvas.

ScrollPane scrollPane = new ScrollPane ();
BorderPane borderPane = new BorderPane();

Group group = new Group();
DoubleProperty zoomProperty = new SimpleDoubleProperty(1);

Scale scaleTransformation = new Scale();
scaleTransformation.xProperty().bind(zoomProperty);
scaleTransformation.yProperty().bind(zoomProperty);

ImageView viewer = new ImageView(getBackgroundImage());
viewer.setFitWidth(600);
viewer.setPreserveRatio(true);
viewer.setDisable(true);
viewer.setSmooth(false);

group.getChildren().add(viewer);

this.addEventFilter(ScrollEvent.SCROLL, new EventHandler<ScrollEvent>(){
  @Override
  public void handle(ScrollEvent se) {
    if (se.isControlDown() && se.getDeltaY() > 0) {
      double value = zoomProperty.get() * 1.1;
      zoomProperty.set(value);
      se.consume();
    } else if (se.isControlDown() && se.getDeltaY() < 0) {
      double value = zoomProperty.get() / 1.1;
      zoomProperty.set(value);
      se.consume();
    }
  }
});

borderPane.setCenter(group);

scrollPane.setHbarPolicy(ScrollBarPolicy.ALWAYS);
scrollPane.setVbarPolicy(ScrollBarPolicy.ALWAYS);
scrollPane setContent(new Group(borderPane));

Thanks for you help.

EDIT The related question and it's answers do not solve my problem (JavaFX ImageView without any smoothing). The solution 1-4 do not work. Only the hack does. I guess I could be related the node structure I use. I've adjusted my code.

Community
  • 1
  • 1
Mr.Mountain
  • 863
  • 8
  • 32
  • Possible duplicate of [JavaFX ImageView without any smoothing](http://stackoverflow.com/questions/16089304/javafx-imageview-without-any-smoothing) – fabian Nov 03 '16 at 09:03
  • The solutions of the accepted answers do not solve my problem. Only the hack does. And as it is a hack, I think that there might be a better answer to this question. – Mr.Mountain Nov 03 '16 at 09:35

1 Answers1

0

I have found one solution (referring to the possible duplicate) and using a variant of method 1.

In my image constructor I set the requested size to something large - so for an image that I know is about 1000 pixels wide I request an image 10000 pixels wide:

Image image = new Image(file.toURI().toString(), 10000.0, 10000.0, true, false);

I am not sure if this is giving a true view of the pixels, or if it is smoothing at a very low level...... but it works for my needs.

DrPhill
  • 614
  • 5
  • 16