我的应用程序从某些外部源收到BufferedImage 。 该图像需要在其他位置生成,我必须将其用作函数的输入。
不幸的是,在某些情况下,我会收到包含锯齿线的图像,因此应应用抗锯齿。
到目前为止,我发现有很多方面具有之前做到这一点BufferedImage对象, 即根据呈现提示设置为Graphics2D对象,然后渲染,但这并不适用于我的情况。
是否有一些简单的方法可以执行此操作而无需诉诸第三方库(由于许可证问题)? 我需要编写自己的抗锯齿后处理功能吗?
我尝试例如:
/**
* @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;
}
基于:
但是,生成的图像显然仍被混淆。