0

I know how to load and display an animated GIF in a javafx window, but what I need is to read the GIF image frame by frame and pixel by pixel. For example with PNG images, I use the PixelReader associated with the loaded Image and I can get the color of each pixel with the getColor(int x, int y) function with something like this :

PixelReader pixelReader = image.getPixelReader();
for (int line = 0; line < imageHeight; line++) {
    for (int column = 0; column < imageWidth; column++) {
                colors[column][line] = pixelReader.getColor(column, line));
    }
}

But if I try the same kind of thing with an animated GIF, getPixelReader() returns null. According to Java doc, it could be because the image is "in a format that is not supported for reading and writing pixels to.".

Does anyone have an other solution?

  • Maybe see [here](https://stackoverflow.com/questions/28183667/how-i-can-stop-an-animated-gif-in-javafx) (this references a third party library for reading animated gifs). – James_D Apr 06 '18 at 17:52
  • JavaFX doesn't have a public API to access pixels of GIFs, nor does standard Java as far as I know. You need to either write the code yourself (not advised) or use a third-party library or code snippet to decode gif data. You can search for third-party libraries by running a google search on "java gif decoder". – jewelsea Apr 06 '18 at 22:20

0 Answers0