1

I'm writting a 3D renderer in java and I want to display a stream of images in JavaFX. I have this function that reads a int array and converts it to an image view, the problem is that it takes 35 to 40ms to execute...

public static ImageView getImage(int[] imageBuffer, int height, int width) {

        WritableImage wr = new WritableImage(width, height);
        PixelWriter pw = wr.getPixelWriter();


        for(int i = 0; i < height; ++i)
            for(int j = 0 ; j < width; ++j)
                pw.setArgb(j, height-1-i, imageBuffer[i*width+j]);

        return new ImageView(wr);
    }

Is there a way I could optimize it?

PS : the (height-1-i) is because the buffer is written upside down (it will be changed)

I thought I could probably pass the image view as an argument and directly writting to it but the only possibility to change it's display is via setImage()?

Matt
  • 15
  • 3
  • Here is a [mjpeg player](https://stackoverflow.com/questions/16721917/display-rtp-mjpeg/16722558#16722558). I don’t know if it would help you or not, it just seemed related to me. – jewelsea Jan 23 '23 at 06:25

1 Answers1

1

This can be done by using the new WritableImage of JavaFX with support for Buffers. With that I was able to shuffle 4K video data into this image in real-time. I have a few examples of how to do that here: https://github.com/mipastgt/JFXToolsAndDemos (VLCJFXVideoPlayer, AWTImage, NativeRenderingCanvas)

mipa
  • 10,369
  • 2
  • 16
  • 35