简体   繁体   中英

Java Anti Aliasing to BufferedImage

I am trying to convert the following code to 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.

In the end I started to use the java-image-scaling library . 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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