Make JavaFX Image Nearest Neighbor (every frame, multiple times per frame)

I'm making a voxel game with JavaFX as a base. No, I'm not using PerspectiveCamera, I'm making my own engine. The issue is that javafx makes images smoothed when they are stretched, which is ABSOLUTELY STUPID AND I HATE IT. You see, voxel games have low resolution textures (something like 16x16), and when you get up close and personal with a block, that could be stretched to thousands of pixels if you have a good monitor. I have tried:
- Changing requested width and height in image constructor (this kinda works, but memory inefficient)
- Setting fit width and height in image view
- Looking through javafx.scene.effects to see if there's an effect to set the smoothing to 0
- Asking chatgpt
- Searching for about 5 hours on google
- Using Canvas (PerspectiveTransform doesn't work, so no good)
- Using java swing BufferedImage
- Looking in the javafx code
Some things that would work but are too slow to be run many times per frame:
- Pixel Reader/Writer resizing
- Loading image from disk with different RW+H
- Loading image from disk to byte[], then using ByteArrayInputStream
- Processing every pixel with canvas
I feel like I forgot one or two things in those lists, but those are enough things for you to (hopefully) understand my frustration. I don't really want to use external libraries as I want no ties to anything other than JavaFX, but if there is no other way, I can do it.

After writing this, I feel like I forgot to clarify what I mean by "smoothing". Image 1 is what I want it to look like (done with RW+H, but that's inefficient), and image 2 is what it looks like normally.
image.png
Screenshot_2024-01-21_140658.png
Was this page helpful?