Skip to main content

Don't Use getScaledInstance() (But Do Read Chris's Article on Why Not)

Posted by chet on April 19, 2007 at 4:31 PM PDT

I should have linked to this when Chris published it, but it slipped my mind in the usual chaos that precedes JavaOne. Chris wrote an excellent article on image scaling, why getScaledInstance() is not your friend, and how you can get both quality and performance in your scaling operations. Go read it now:

The Perils of Image.getScaledInstance().

The funny part, for me, is that we did this article in parallel. I'd been thinking about doing an article on this exact topic for years. I had even started it a couple of years back, but deadlocked when I realized that I needed some nice demo code and screen shots (which Chris's article has) to go along with it. So it sat on the back burner until I found myself in the middle of writing a certain book, and wanted to discuss the topic in a chapter on Images. I wrote up a draft of the section, complete with demo and screenshots, sent it to Chris to review ... and he replied that he'd just written the article.

Great Scaled Coincidences!

In the end, you'll get to see both of them. I kept my section in the book and my demo as-is, and Chris finished his article up quite nicely.
I'd like to say that they hit the market at the same time, but given the realities of book publishing, Chris's article is out way before the book. Dangit.

Anyway, go read the article. Good stuff, and easy fixes for slow image scaling code.

Related Topics >>