0

In my JavaFX app, I have to draw a large memory bitmap and provide zooming functionality. Bits can be pass (green) or fail (red). I started working with a java.awt.image.BufferedImage converted to a JavaFX ImageView, but I could not get a pixel sharp representation of bits on adjacent pass/fail bits border with a large zoom factor. I then tried working with Canvas, and I stumbled across the same blurry image issue on adjacent colors. I finally discovered Shape objects which remain pixel sharp even with large zooming factors, but the number of Shapes I have to manage is so large that my app stops with an OutOfMemoryError (too many objects added to the Group children list). I did some experiments with Shape.union but I lost the Bit pass/fail color information.

Is there a way to combine Shapes which fulfills my requirements: memory usage, color control and... execution time?

    Bit[][] bits = ...;

    Group root = new Group();

    Shape rect = new Rectangle(0.0, 0.0, width, height);
    rect.setFill(javafx.scene.paint.Color.GREEN);
    root.getChildren().add(rect);

    for (int x = 0; x < width; x++)
    {
        for (int y = 0; y < height; y++)
        {
            Line line = new Line(x + 0.5f, y + 0.5f, x + 0.5f, y + 0.5f);

            if (!bits[y][x].getStatus())
            {
                line.setStroke(javafx.scene.paint.Color.RED);
            }
            else if (bits[y][x].getNature() == BitNature.ECC)
            {
                line.setStroke(javafx.scene.paint.Color.BLUE);
            }
            root.getChildren().add(line);
        }
    }
Georgie
  • 77
  • 6
  • You're dealing with the issue presented here: https://stackoverflow.com/questions/16089304/javafx-imageview-without-any-smoothing BTW: I wouldn't use lines to represent quadratic shapes. Use `Rectangle` instead. However I'd go with a `Canvas` and instead of using the `scale` properties simply draw the rects in the appropriate size (round to intgral values to keep the borders nice and sharp). It could also help to "virtualize" the display assuming you're not always showing the full results on screen but use a `ScrollPane` or something like this: – fabian Jul 11 '18 at 13:21
  • You only keep nodes that are visible on screen/keep the canvas size at the size of the viewport bounds... – fabian Jul 11 '18 at 13:22
  • This is a smart solution @fabian thank you ! – Georgie Jul 13 '18 at 09:00

0 Answers0