0

How draw a crisp, opaque hairline in JavaFX without changing the coordinates.My shape x,y can not change,even 0.1。By modifying x,y to 0.5 ,it does not apply to me. My line x, y value is uncontrollable. When my value is fixed, I can get a thin line. Now X and Y have integers and decimals.5 or even.4, .3, and .2 In this case, there will be both thin and thick lines.

We are using javafx to develop a scalable graphics program. Considering the performance, we use javafx canvas to draw a lot of rectangular boxes. The rectangular box represents the position of the container. We found that the rectangle will appear thick and thin lines, blurred and so on. Our graphics need to be scaled. The calculated width and coordinates of the rectangular frame will have floating point numbers. We can't solve the problem by using the following post. After scaling, the coordinates of 0.5 must not exist, if the conversion will be inaccurate.Anyway, thank you for any help. How to draw a crisp, opaque hairline in JavaFX 2.2? This is my example.After I scroll the mouse, the rectangle lines become blurred.

import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.input.ScrollEvent;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
public class LineScaleTest extends Application {
public static void main(String[] args) { launch(args); }

@Override public void start(Stage stage) {
    AnchorPane anchorPane=new AnchorPane();
    Canvas canvas=new Canvas(500,300);
    canvas.relocate(300,300);
    GraphicsContext gc=canvas.getGraphicsContext2D();
    for(int i=0;i<10;i++){
        gc.strokeRoundRect(10.5+35*i,5.5,30,30,0,0);
    }

    for(int i=0;i<10;i++){
        gc.strokeRoundRect(10.5+35*i,65.5,30,30,0,0);
    }

    for(int i=0;i<10;i++){
        gc.strokeRoundRect(10.5+35*i,115.5,30,30,0,0);
    }

    anchorPane.setOnScroll(new EventHandler<ScrollEvent>() {
        @Override
        public void handle(ScrollEvent e) {
            if (e.getDeltaY() == 0) {
                return;
            }
            double scaleFactor = (e.getDeltaY() > 0) ? 1.1
                    : 1 / 1.1;
            anchorPane.setScaleX(anchorPane.getScaleX() * scaleFactor);
            anchorPane.setScaleY(anchorPane.getScaleY() * scaleFactor);
        }
    });
    anchorPane.getChildren().add(canvas);
    Scene scene = new Scene( anchorPane,1200, 700);
    stage.setScene(scene);
    stage.show();
}
}
pudd
  • 1
  • 1
  • Thank you.This idea does not apply to me. I have studied this idea. My line x, y value is uncontrollable. When my value is fixed, I can get a thin line. Now X and Y have integers and decimals.5 or even. 4, .3, and .2 In this case, there will be both thin and thick lines. – pudd Sep 30 '18 at 03:26
  • Are you just creating new accounts and posting the same question. It would serve you better to create a better question. https://stackoverflow.com/questions/52573800/javafx-canvas-zoom-in-and-out-distortion-problem – SedJ601 Sep 30 '18 at 05:02

0 Answers0