我在放大大图像时遇到问题。当我将图像放大很多并移动图像时(可缩放功能),我会松开一块图像(如裁切)。我的代码哪里有错误?
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);