java - What is the best way to read pixels of a JavaFX Canvas? -
i want color specific coordinates inside canvas
. tried getting snapshot using code:
writableimage snap = gc.getcanvas().snapshot(null, null); snap.getpixelreader().getargb(x, y); //this gets color without assigning it.
but takes time application. wondering if there other way access color of pixel know coordinates.
a canvas
buffers drawing instructions prescribed invoking methods of graphicscontext
. there are no pixels read until canvas
rendered in later pulse, , internal format of instruction buffer not exposed in api.
as alternative, consider drawing bufferedimage
, illustrated here, allows access image's pixels directly , via writableraster
. adding following line complete example outputs expected value opaque red in argb order: ffff0000
.
system.out.println(integer.tohexstring(bi.getrgb(50, 550)));
Comments
Post a Comment