Home > Blockchain >  Stream an image in JavaFX
Stream an image in JavaFX

Time:01-23

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()?

CodePudding user response:

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)

  • Related