开发者

Resized image degrades in quality

开发者 https://www.devze.com 2022-12-22 15:04 出处:网络
I resized an image using Java2D Graphics class. But it doesn\'t look right. BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, type);

I resized an image using Java2D Graphics class. But it doesn't look right.

    BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, type);
    Graphics2D g = resizedImag开发者_JAVA技巧e.createGraphics();
    g.drawImage(originalImage, 0, 0, IMG_WIDTH, IMG_HEIGHT, null);
    g.dispose();

Is it possible to scale an image without introducing artifacts?


Bitmap graphics do not scale well, generally speaking. Degradation is particularly notable when you increase the size of the image, but even scaling down can introduce undesirable artifacts especially if not scaling by integral factors.

The best solution, if you need multiple sizes of a single image for display, is to either use vector* graphics or take the highest fidelity bitmap you have and scale down, and by integral factors.

*Note that vector graphics aren't an option for photographs and the like.


This article by Chris Campbell has lots of detailed information on scaling images with Java2D.

There are a number of options you can use regarding the quality of the scaling, where generally the better the quality the longer the scaling will take (performance versus quality tradeoff).

The information in the article will probably help your scaling look better, but as @Kevin says in his answer, at the end of the day no scaling is going to be absolutely perfect.


You could look into java-image-scaling library. With a quick test it created a better quality down scaled image than using standard Java2D/AWT tools.

0

精彩评论

暂无评论...
验证码 换一张
取 消