Re-calibration Java image - nearest neighbor
I'm trying to resize an image using Java and I need to get the exact effect that happens when Photoshop's Nearest Neighbor is resized (keep hard edges).
The thing is, I never get the exact effect ...
I've tried the following methods:
1) java-image-scale by mortennobel lib
this works great, but leaves some artifacts in the image that are not there when Photoshop does it.
2) TwelveMonkeys library for image processing. ( here is the github link ) Doesn't work, PointFilter destroys the gradient inside completely, and Box filter does the same as mortennobel getBoxFilter.
3) AWT AffineTransform, it was the worst, totally unrealistic size.
Now I'm confused if photoshop's nearest neighbor resized differently than what that name means, or all other libraries are doing it wrong (in the second case, what is the lib that will do it right?)
Here are the before and after images Photoshop generates
And here is the image generated by get BoxFilter from mortennobel lib.
I scaled the images a little so you can see the details, they are actually smaller. Any help is really appreciated :) I'm really stuck on this one.
source to share
Many thanks to Marco13 for this! Apparently the mortennobel lib doesn't make the nearest neighbor, instead AWT Graphics2D can be used with the RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR rendering hint. Here is a piece of code that worked for me and created an accurate Photoshop image.
destinationBufferedImage = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = destinationBufferedImage.createGraphics(); g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); g2.drawImage(sourceBufferedImage, 0, 0, newWidth, newHeight, null); g2.dispose();
source to share