Venkat
Venkat

Reputation: 21490

Resized image degrades in quality

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 = resizedImage.createGraphics();
    g.drawImage(originalImage, 0, 0, IMG_WIDTH, IMG_HEIGHT, null);
    g.dispose();

Is it possible to scale an image without introducing artifacts?

Upvotes: 0

Views: 866

Answers (3)

Juha Syrjälä
Juha Syrjälä

Reputation: 34281

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.

Upvotes: 0

Ash
Ash

Reputation: 9446

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.

Upvotes: 0

Kevin Montrose
Kevin Montrose

Reputation: 22611

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.

Upvotes: 1

Related Questions