I'm trying to zoom with a slider a selected image in ImageView. The only thing that I am able to do is to resize whole ImageView with the image in it. But this is not what i am searching for. I want to zoom only the image with ImageView having the same size. It should be a demonstration of a focal length. I'm using also scene builder.I'm only beginner in all of this, so I would really appreciate your help. Here's what I have.
public void openImage(ActionEvent event) {
FileChooser fc = new FileChooser();
File f = fc.showOpenDialog(null);
if (f != null) {
System.out.println(f.toURI().toString());
Obrazok = new Image(f.toURI().toString());
imageView.setImage(Obrazok);
imageView.setSmooth(true);
imageView.setCache(true);
}
}
public void setOnZoom (MouseEvent e){
imageView.scaleXProperty().bind(slider.valueProperty());
imageView.scaleYProperty().bind(slider.valueProperty());
Rectangle2D viewpoint = new Rectangle2D(0, 0, Obrazok.getRequestedHeight(), Obrazok.getRequestedWidth());
imageView.setViewport(viewpoint);
imageView.setViewport(viewpoint);
imageView.setImage(Obrazok);
}
i'm not really sure what you wanted to do ! and i kind of used James_D suggestion
alright i'm a Beginner too and it took me almost two hours to write this for you, hope anyone read this and find it useful
i only added ExtensionFilters for png and jpg but you can add any extension that is supported by javaFx
(i used sliders instead of scrollbars cause i hate dealing with scrollbars but i'm sure you can do it yourself)
screenshot 01
screenshot 02
screenshot 03
screenshot 04
Update : now you can drag on the imageview to move the viewport