Quality scaling of 2D images?

Dear all,

Has anybody figured out how to scale large (2000x2000) 2D images in Java (using AWT, Java2D or JAI) to the same quality as that produced by, say, Paint Shop Pro or PhotoShop?

The Internet is awash with people who have discovered that…

image.getScaledInstance

…produces significantly better results (on a par with Paint Shop or PhotoShop) than, say…

graphics.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR );

…but the former seems like a really old implementation, is very slow and (worst of all) doesn’t co-exist very well with things like…


graphics.translate( iX, iY );
graphics.scale( dX, dY );

:frowning:

So, the ‘getScaledInstance’ anamoly aside, how do you get good, smooth scaled large images out of Java?

If you have a large, cartoony image (like a line drawing, but with colours) how do you resize it down to as good a job as Paint Shop Pro does?

Have you tried using Graphics2D (i.e. cast Graphics to Graphics2D) and then use


g2d.drawImage(image,AffineTransform.getScaledInstance(0.5,0.5),null) 

This uses the newest stuff I know of for scaling images and will work happily with translates and scales. But those should probably be done with AffineTransforms and setTransform() now.

Kev

Yeah - unfortunately that seems to use the same code (or at least produces the same result) as a ‘drawImage’ with width/height parameters - rather poor quality :frowning:

If you try it, you should see a marked difference between that and using ‘Image.getScaledInstance’.

Let me know if you don’t…

If it’s just about cartoony images… vector based graphics would look best. Scaling is much faster and the image quality will be much better.

http://www.geocities.com/marcoschmidt.geo/java-image-coding.html (link sponsored by kevglass ;))

Interpolation is only used when scaling UP. If you are scaling down you will need to do filtering.

At any rate there are rendering hints that you haven’t mentioned…
I would try:
KEY_ANTIALIASING = VALUE_ANTIALIAS_ON
KEY_RENDERING = VALUE_RENDER_QUALITY
KEY_COLOR_RENDERING = VALUE_COLOR_RENDER_QUALITY