How to resize a image without losing quality using java?
Asked Answered
P

2

2

My requirement is:"How to resize the image without loosing quality using swing".

I am using resizer components,label,panel. I am using resizing concept at this time image is blurring and lose the quality. so any one do you know "how to resize the image without loosing the quality using swing concept?". Send me the related information or code.

Thank You, GaneshKumar.

Pycnidium answered 15/8, 2012 at 10:8 Comment(1)
are you trying to reduce or increase the size of your image? What do you mean by quality? Could you post an example of an image before and after resizing?Gradate
M
5

Ganesh,

You might take a look at imgscalr, it is an extremely simple (single class, bunch of static methods to use) that looks like this to use:

BufferedImage thumbnail = Scalr.resize(srcImage, 150);

To ensure the highest-quality scaled result, you can pass additional arguments to the resize method like so:

BufferedImage thumbnail = resize(img, Method.ULTRA_QUALITY, 125, OP_ANTIALIAS);

There are also a slew of simple image operations (like cropping, padding, rotating, etc.) that you can use as well. There is also an asynchronous class that can queue up many operations at once and execute them in a configurable number of threads if you are doing image processing on a server for example.

The library is written in pure Java and released under the Apache 2 license, you can find all the source code here if you are interested.

Here are some other SO questions related to it if you are curious about other examples or use-cases.

Mystery answered 21/8, 2012 at 17:1 Comment(0)
C
2

What you're asking for is impossible. Scaling a raster image where new resolution > native resolution is by definition lossy. If by any chance I misunderstood the question, I apologize in advance.

Confocal answered 21/8, 2012 at 16:57 Comment(3)
What I believe is being asked is that when getting a scaled the image gets REALLY blurry, not just loses quality... it becomes extremely bad quality -- I have had this issue, too, but never found a good solution for it.Bedmate
this not true. Scaling up the size of an image can be lossless if the scaling factor is an integer. Scaling down is always lossy.Gradate
I think, as you said, it depends on what he means by quality. Although scaling up an image with scaling factor as an integer, anti-aliasing pixels will cover more area which will make it look less smooth.Cirrocumulus

© 2022 - 2024 — McMap. All rights reserved.