0

I have a problem with zooming large image. When i zooming image to much and I move my image (pannable function) I loose a piece of image (like cut). Where is mistake in my code?

private void zoom(ImageView imagePannable) {
    imagePannable.setOnScroll(
            new EventHandler<ScrollEvent>() {
        @Override
        public void handle(ScrollEvent event) {
            double zoomFactor = 1.20;
            double deltaY = event.getDeltaY();

            if (deltaY < 0) {
                zoomFactor = 0.80;
            }
            else
                zoomFactor = 1.20;

            imagePannable.setFitHeight(imagePannable.getFitHeight() * zoomFactor);
            imagePannable.setFitWidth(imagePannable.getFitWidth() * zoomFactor);

            event.consume();
       }
    });
}
double propX = viewportBounds.getWidth() / image.getWidth();
double propY = viewportBounds.getHeight() / image.getHeight();

imageView.setFitWidth(imageView.getImage().getWidth() * propX);
imageView.setFitHeight(imageView.getImage().getHeight() * propY);


scrollPane.setContent(imageView);

scrollPane.setPannable(true);
// center the scroll contents.
scrollPane.setHvalue(0.5);
scrollPane.setVvalue(0.5);

zoom(imageView);
fabian
  • 80,457
  • 12
  • 86
  • 114
marcin panek
  • 117
  • 2
  • 9
  • Take a look at this question and see if any of the answers are helpful: https://stackoverflow.com/questions/39529840/javafx-setfitheight-setfitwidth-for-an-image-used-within-a-scrollpane-disabl – MMAdams Jul 06 '18 at 13:18
  • I couldn't reproduce this but some things are just weird: You seem to set the initial `fitWidth` during initialisation, i.e. before the first layout pass. At that time the `viewportBouns` should have the size 0 x 0. Furthermore you're using some calculation for the size you want the image to be fitted to that should result in the exact same size as the viewport bounds, so why not use those directly? – fabian Jul 06 '18 at 13:23

0 Answers0