White pixeldata is read after the canvas is cleared

1

I want to read out a Canvas's pixel data (using OpenJFX 12), and do some checks on it.

int x = ...;
int y = ...;
Canvas canvas = ...;
WritableImage snapshot = canvas.snapshot(null, null);
PixelReader pixelReader = snapshot.getPixelReader();
Color color = pixelReader.getColor(x, y);

This works except that if the canvas were cleared with canvas.getGraphicsContext2D().clearRect(...), color will be 0xffffffff, which is white, fully visible, but it should be 0x00000000, as the documentation says. The drawn image is correct, where it sould be transparent, it is, because I see items behind it.

I'm also using TestFX (right now in visible mode), but I don't think that affects the canvas' data.

Why is that? Maybe I misunderstand what clearRect do?

canvas
javafx
asked on Stack Overflow Apr 13, 2019 by klenium

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0