简体   繁体   English

Java抗锯齿化到BufferedImage

[英]Java Anti Aliasing to BufferedImage

I am trying to convert the following code to Java: 我正在尝试将以下代码转换为Java:

image = PIL.Image.open(iconFile)

image = image.convert('L').resize(
    (9, 8),
    Image.ANTIALIAS,
)

--> - >

BufferedImage picture = ImageIO.read(new File(iconFile));

int IMG_WIDTH = 9;
int IMG_HEIGHT = 8;

BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, BufferedImage.TYPE_BYTE_GRAY);
Graphics2D g = resizedImage.createGraphics();

g.drawImage(picture, 0, 0, IMG_WIDTH, IMG_HEIGHT, null);
g.dispose();

How do I perform the anti aliasing operation? 如何执行抗锯齿操作? My app is a command line tool which scales images. 我的应用程序是可缩放图像的命令行工具。

I recently had to do this too. 我最近也必须这样做。 I found that the Java default image rescale operations were not suitable for downsizing image and left a low quality finish. 我发现Java默认的图像缩放操作不适用于缩小图像的尺寸,并留下了低质量的效果。

In the end I started to use the java-image-scaling library . 最后,我开始使用java-image-scaling库 Its very good and easy to use and provides a very good finish. 它非常好并且易​​于使用,并且提供了很好的光洁度。

A sample usage would be: 用法示例为:

ResampleOp  resampleOp = new ResampleOp (100,200);
BufferedImage destImage= resampleOp.filter(sourceImage, null);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM