png – Scaling images/icons in Java – Education Career Blog

A project I am working on needs to be resized when the monitor resolution changes. Due to legacy code and other issues, we do it by using a custom library which scales all the components to the appropriate sizes when the resolution changes.

However, when we scale some of the images/icons used in the project, they become blurry/fuzzy/aliased. Mostly because they are all raster gifs.

One solution we thought might work to mitigate this issue is to either use Vector images and convert them into raster images on the fly (and cache them for performance improvements).

What do you all think? Would this be a good way to go? Or are there better alternatives to my chosen method?

If this is a better way, then can someone give pointers to how to go about the svg conversion to say jpg or png(preferably). Available (and commercially usable) libraries?



The algo’s in java are pretty good. The fundamental problem sounds as if your original images/icons are already too small so scaling them up leaves you with artefacts. A real simple approach is to have the images sent along with the app to be at the larger size and only scale down. I would say a policy on images sizes (pixels height and width) is necessary as you seem to indicate that only some have problems.

Of course if you can go for vector graphics, you can scale infinitely and this may be a better long term investments depending upon your application and the likely hood of needing to support large output formats (not just screens but printing). It may well be fairly complex to approach things this way. (More information would be needed to help you further with the points in this para.)


Batik can convert svgs into pngs or jpegs


The icons in the Metal (cross-platform) PL&F are drawn into a buffered image, in order to blend in with whatever machine it happens to find itself running on. It’s a fast technique, doesn’t add dependencies and there’s no need to learn any extra APIs (or languages!). See in your Sun JDK.

Leave a Comment