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