Question

I'm making a small game in Java, and it uses a pixel-graphics style, with many sprites 16x16 or 32x32 pixels. However, when I rotate them, I do not want "jaggies" along the side, so I used the RenderingHint

RenderingHint.KEY_INTERPOLATION
RenderingHint.VALUE_INTERPOLATION_BILINEAR

Unfortunately, because many of the images used are very small (16x16, 32x32) the resulting image is completely unusable. Output:

https://i.stack.imgur.com/4qKSk.jpg

As you can see, the small graphics are blurred. This is the intended effect for large images, but for small images, it is very bad.

One solution is to increase the resolution of all my graphics, while keeping the "blocky" effect. That would be a pain, so is there another way to tweak the interpolation?

Thank you guys so much.

Was it helpful?

Solution

Upscale your tiny images and use that instead:

BufferedImage tiny = ImageIO.read(new File("..."));
BufferedImage bigger = new BufferedImage(tiny.getWidth()*10, tiny.getHeight()*10, tiny.getType());
Graphics2D g = bigger.createGraphics();
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
g.drawImage(tiny, 0, 0, bigger.getWidth(), bigger.getHeight(), 0, 0, tiny.getWidth(), tiny.getHeight(), null);

Replace the 10 scaling factor by the smallest value that gives acceptable results.

Do the rest of your rendering with high quality interpolation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top