My application receives a BufferedImage
from some external source. This image needs to be generated elsewhere and I have to use it as input for my function.
Unfortunately in some cases I will receive images that contain jagged lines, therefore antialiasing should be applied.
So far I have found many ways to do this before having the BufferedImage
object, i.e. setting the according rendering hints to the Graphics2D
object and then rendering, but this is not applicable in my situation.
Is there some simple way to do this, without resorting to 3rd party libraries (due to license concerns)? Do I need to write my own antialiasing-postprocessing-function?
I tried for example:
/**
* @brief apply antialiasing to {@link BufferedImage} object. Take note that this will also increase image dimensions by 2px!
* @param image
* @return
*/
public static BufferedImage applyAntialiasing( BufferedImage image )
{
BufferedImage antialiasedImage = new BufferedImage( image.getWidth() + 2, image.getHeight() + 2, BufferedImage.TYPE_INT_ARGB );
Graphics2D g = ( Graphics2D ) antialiasedImage.createGraphics();
( ( Graphics2D ) g ).setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
g.drawImage( image, 1, 1, null );
g.dispose();
return antialiasedImage;
}
which is based on:
Java Graphics2D drawImage() and clip(): how to apply antialiasing?
However the resulting image is clearly still aliased.