0

I would like a high-quality way to scale images, in particular JPEG images, using Java. I looked into this extensively around 2007, and at the time JAI had problems that would produce black borders in some scaled images.

Back then I finally settled on a technique of using Image.getScaledInstance() and writing to a BufferedImage with Graphics2D rendering hints, modified from a technique described by Perry Nguyen. This approach was slower, but produced images virtually identical in quality to JAI subsample average, but without the incorrect borders.

In revisiting this I did some quick research, but I don't see that there is any better way to do this than there was almost 15 years ago. However I did find Apache Commons Imaging, a new project that claims to only use Java, so it promising. Unfortunately I couldn't find any documentation on scaling images.

Does Apache Common Imaging handle high-quality scaling of images? If so, where can I find documentation?

Garret Wilson
  • 18,219
  • 30
  • 144
  • 272
  • @MichaelEaster, that looked interesting until I saw that it was no longer maintained, and moreover the project-related site (see the README) has been abandoned and hijacked (see the issues) and seem to be trying to spread viruses. I realize that doesn't directly affect the code in GitHub, but it doesn't give me confidence in the project being maintained and stable. – Garret Wilson Oct 30 '20 at 16:45
  • Ah, apologies... I didn't study the current state very well. I've removed my original comment (to remove the link), but for others: I had recommended "imgscalr". But it sounds like it should be *avoided*. – Michael Easter Oct 30 '20 at 17:13

1 Answers1

1

Please, take a look at Patrick Favre's density-converter library.

It is mainly a command line and GUI image processing tool designed for mobile (Android, iOS) systems.

But even in the case you are looking for a way to integrate it with your code, please review the scaling mechanism implementation performed in the ImageHandler class and the different algorithms defined in the package at.favre.tools.dconvert.converters.scaling, I think it could be helpful.

jccampanero
  • 50,989
  • 3
  • 20
  • 49