Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/342.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在JavaFX中使用_Java_Javafx_Java 8_Javafx 2_Javafx 8 - Fatal编程技术网

如何在JavaFX中使用

如何在JavaFX中使用,java,javafx,java-8,javafx-2,javafx-8,Java,Javafx,Java 8,Javafx 2,Javafx 8,我正在尝试做一个程序来绘制图像上的多边形,我们可以缩放图像和多边形后点击缩放按钮。 单击“缩放”按钮后,图像将被裁剪。为了避免这个问题,我使用stackpane 我试着设置AnchorPane的X和Y比例,这可以完美地缩放图像和多边形,但多边形并没有在窗格中完美设置。图像的顶部和右侧脱离了窗格 我尝试使用画布设置X和Y比例,但只有图像在缩放,而不是绘制多边形 getView().getCanvas().setScaleX(getView().getCanvas().getScaleX() * z

我正在尝试做一个程序来绘制图像上的多边形,我们可以缩放图像和多边形后点击缩放按钮。 单击“缩放”按钮后,图像将被裁剪。为了避免这个问题,我使用stackpane

我试着设置AnchorPane的X和Y比例,这可以完美地缩放图像和多边形,但多边形并没有在窗格中完美设置。图像的顶部和右侧脱离了窗格

我尝试使用画布设置X和Y比例,但只有图像在缩放,而不是绘制多边形

getView().getCanvas().setScaleX(getView().getCanvas().getScaleX() * zoomFactor);
getView().getCanvas().setScaleY(getView().getCanvas().getScaleY() * zoomFactor);
要缩放图像和绘制多边形,我需要API的建议

    private void setImageAndCanvas() { 
                scrollPane = new ScrollPane(); 
                anchorPane = new AnchorPane(); 
                canvas = new Canvas(screenWidth/2, screenHeight-120); 
                gridLines = new ArrayList<Line>(); 
                imageSections = new ArrayList<Polygon>(); 
                scrollPane.setContent(anchorPane); 
                anchorPane.getChildren().add(canvas); 
                scrollPane.setPrefSize(screenWidth/2, screenHeight-120); 
        }

`public void setCanvas(Canvas canvas, Image img){
        graphicsContext.drawImage(img, 0, 0, canvas.getWidth(), canvas.getHeight());
    }`

    private void zoom(double zoomFactor) {
        zoomWidth.set(zoomWidth.get() * zoomFactor);
        zoomHeight.set(zoomHeight.get() * zoomFactor);
        getView().getAnchorPane().setScaleX(getView().getAnchorPane().getScaleX() * zoomFactor);
        getView().getAnchorPane().setScaleY(getView().getAnchorPane().getScaleY() * zoomFactor);
        zoomCounter = zoomFactor>1 ? ++zoomCounter: --zoomCounter;
        if (zoomCounter > 0 && zoomCounter < 3) {
            getView().getZoomIn().setDisable(false);
            getView().getZoomOut().setDisable(false);
        }
    }

    public void zoomOutAction(ActionEvent event) {
        zoom(1/zoomFactor);
        event.consume();
    }

    private void drawAllImageSections(){
        if(getView().getImageNameTablePane().getSelectedItem()!=null){
            String imageName = getView().getImageNameTablePane().getSelectedItem().getImageName();
            List<QiImageSectionPoint> polygonPoints = getModel().showAllImageSection(imageName);
            if(!polygonPoints.isEmpty()){
                List<Double> allPointsList = new ArrayList<Double>();
                double resizeWidthPercent = ((getView().getScreenWidth()/2)-500)/5;
                double resizeHeightPercent = ((getView().getScreenHeight()-120)-500)/5;
                polygon = new Polygon();
                for(int i = 0; i<polygonPoints.size(); i++){
                    int imageSectionId = polygonPoints.get(i).getImageSectionId();
                    if((i+1)<polygonPoints.size() && imageSectionId == polygonPoints.get(i+1).getImageSectionId()){
                        allPointsList.add((double) polygonPoints.get(i).getPointX()+((polygonPoints.get(i).getPointX()*resizeWidthPercent)/100));
                        allPointsList.add((double) polygonPoints.get(i).getPointY()+((polygonPoints.get(i).getPointY()*resizeHeightPercent)/100));
                    }else{
                        allPointsList.add((double) polygonPoints.get(i).getPointX()+((polygonPoints.get(i).getPointX()*resizeWidthPercent)/100));
                        allPointsList.add((double) polygonPoints.get(i).getPointY()+((polygonPoints.get(i).getPointY()*resizeHeightPercent)/100));
                        polygon.getPoints().setAll(allPointsList);
                        polygon.setFill(null);
                        polygon.setStroke(lineColor);
                        polygon.setStrokeWidth(lineWidth);
                        getView().getImageSections().add(polygon);
                        allPointsList = new ArrayList<Double>();
                        polygon = new Polygon();
                    }
                }
            }
        }
        if(getView().getImageSections()!=null)
        getView().getAnchorPane().getChildren().addAll(getView().getImageSections());
    }
private void setImageAndCanvas(){
scrollPane=新的scrollPane();
锚烷=新锚烷();
画布=新画布(屏幕宽度/2,屏幕高度-120);
gridLines=新的ArrayList();
imageSections=新的ArrayList();
滚动窗格。设置内容(anchorPane);
anchorPane.getChildren().add(画布);
scrollPane.setPrefSize(屏幕宽度/2,屏幕高度-120);
}
`公共void setCanvas(画布画布、图像img){
graphicsContext.drawImage(img,0,0,canvas.getWidth(),canvas.getHeight());
}`
专用空心缩放(双缩放因子){
set(zoomWidth.get()*zoomFactor);
set(zoomHeight.get()*zoomFactor);
getView().GetAncorpane().setScaleX(getView().GetAncorpane().getScaleX()*zoomFactor);
getView().GetAncorpane().setScaleY(getView().GetAncorpane().getScaleY()*zoomFactor);
zoomCounter=zoomFactor>1?++zoomCounter:--zoomCounter;
如果(zoomCounter>0&&zoomCounter<3){
getView().getZoomIn().setDisable(false);
getView().getZoomOut().setDisable(false);
}
}
公共空间活动(ActionEvent事件){
缩放(1/zoomFactor);
event.consume();
}
私有无效drawAllImageSections(){
如果(getView().getImageNameTablePane().getSelectedItem()!=null){
字符串imageName=getView().getImageNameTablePane().getSelectedItem().getImageName();
列出polygonPoints=getModel().showAllImageSection(imageName);
如果(!polygonPoints.isEmpty()){
List allPointsList=new ArrayList();
双尺寸宽度百分比=((getView().getScreenWidth()/2)-500)/5;
双尺寸高度百分比=((getView().getScreenHeight()-120)-500)/5;
多边形=新多边形();
对于(int i=0;i