0

Is it possible to use JavaFX to manipulate pixels like in Swing? Using an array of ints like this:

int[] buffer = ((DataBufferInt) image.getRaster().getDataBuffer()).getData();

This was using a buffered image, but I'm not sure what to change to get pixels like this in JavaFX. Edit: I would like to be able to edit any pixel in the frame in a while loop.

Si1kn s
  • 1
  • 1
  • 1
    Does this help https://stackoverflow.com/questions/43036581/change-a-color-image-to-red-green-or-blue-in-javafx – JCompetence Sep 29 '21 at 12:42
  • Thank you, unfortuneatly, I can't apply it here. I would like to be able to edit the pixels inside the frame with a while loop, but thank you for the responce! – Si1kn s Sep 29 '21 at 12:53
  • 1
    It's not clear how the question linked above is different. Use a `WritableImage`, and you can manipulate the pixel data via its `PixelWriter`. In JavaFX 13 and later, you can also create a `WritableImage` using a `PixelBuffer`, and then manipulate the underlying buffer. – James_D Sep 29 '21 at 13:42
  • 1
    Here's an example which continually updates JavaFX images: https://stackoverflow.com/questions/60668758/how-to-show-images-in-a-large-frequency-in-javafx/60672547#60672547 – James_D Sep 29 '21 at 13:51
  • 2
    There are likely numerous similar questions and a few different ways of doing this using PixelReader and PixelWriter methods. Here is another: [which reduces the color palette of an image](https://stackoverflow.com/questions/12941600/reduce-number-of-colors-and-get-color-of-a-single-pixel) – jewelsea Sep 29 '21 at 16:07
  • 1
    It's not clear if your use case can avoid the extra baggage, but an example using `BufferedImage` is examined [here](https://stackoverflow.com/a/44141878/230513). – trashgod Sep 29 '21 at 16:11

0 Answers0