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);
}
}