Java - Good and free library to resize images [closed]

扶醉桌前 提交于 2019-12-12 18:45:56

问题


I want to resize images in java.

Until now i use this:

BufferedImage resizedImage = new BufferedImage((int) new_dim.getWidth(), (int) new_dim.getHeight(), type);
Graphics2D g = resizedImage.createGraphics();
g.drawImage(originalImage, 0, 0, (int) new_dim.getWidth(), (int) new_dim.getHeight(), null);
g.dispose();

with newDim being an Dimension.

But the results are very poor in quality ...

Is there some commercial free library that does this simple job ?


回答1:


You should try out imgscalr:

https://github.com/thebuzzmedia/imgscalr

http://www.htmlgoodies.com/beyond/java/create-high-quality-thumbnails-using-the-imgscalr-library.html




回答2:


Thumbnailator is an open-source (MIT license) library which specializes image resizing operations, especially in shrinking images.

For example, the following will resize a BufferedImage:

BufferedImage sourceImage = // ...
BufferedImage resizedImage = 
    Thumbnails.of(sourceImage)
        .size(newWidth, newHeight)
        .asBufferedImage();

Thumbnailator provides flexible inputs and outputs, so it's possible to mix and match File and BufferedImage inputs and outputs:

BufferedImage sourceImage = // ...
Thumbnails.of(sourceImage)
    .size(newWidth, newHeight)
    .toFile(destinationFile);

or

File sourceFile = // ...
BufferedImage resizedImage = 
    Thumbnails.of(sourceFile)
        .size(newWidth, newHeight)
        .asBufferedImage();

The library uses techniques to improve the quality of the resized image, and does it while maintaining a good balance between speed and quality. The Thumbnailator project page has a image quality comparison.

Disclaimer: I am the maintainer of the library




回答3:


Attempt to convince you to reconsider, at least about the quality

You could try with g.setRenderingHints(KEY_INTERPOLATION, VALUE_INTERPOLATION_BICUBIC); see this.

There are also ImageFilters, for sharpening and such.



来源:https://stackoverflow.com/questions/13892725/java-good-and-free-library-to-resize-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!