I do not know java (usually write in c)
How can I do efficiently some way of blitting
pixel array content onto a window in java?
I need (in loop) blit pixels[][] onto a window
I could use something like
pixels[][] -> MemoryImageSource -> Image -> drawImage
but creating and deleting MemoryImageSource and Image
in every frame seems strange to me – how it can be
done simply and reasonably efficiently? Could someone
give a code example, tnx
Normally in Java it’s easier to work with the native
Imagetypes and use their derived graphics. Behind the scenes Java uses blits as well, so the higher level abstractions is made to easen the workload.But if there’s no way to abstract on the pixel data you can use Raster and WritableRaster (where you can replace portions of the array) as an alternative to your solution. These rasters can be used with a BufferedImage which then can be drawn using the drawImage method you mentioned. I found one way of doing it here which basically creates the Image and then retrieves the raster for future manipulation.
That raster (or just small areas of it) can then be manipulated and repainted.
This might improve performance slightly since the distance from you pixel-array to the screen is shorter. But I think very few people fully understands the entire depths of the AWT api – and it all depends on the native implementations of course – so my idea contains a healthy part of speculation 😉
But I hope it helped..