<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Noa&#039;s blog &#187; Image resizing</title>
	<atom:link href="http://noa.resare.com/tag/image-resizing/feed/" rel="self" type="application/rss+xml" />
	<link>http://noa.resare.com</link>
	<description>moderately interesting words about things going through my mind</description>
	<lastBuildDate>Fri, 29 Jan 2010 23:56:06 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Image resizing in java</title>
		<link>http://noa.resare.com/2008/12/image-resizing-in-java/</link>
		<comments>http://noa.resare.com/2008/12/image-resizing-in-java/#comments</comments>
		<pubDate>Fri, 19 Dec 2008 22:50:17 +0000</pubDate>
		<dc:creator>noa</dc:creator>
				<category><![CDATA[Geeky]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Image resizing]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Java2D]]></category>

		<guid isPermaLink="false">http://noa.resare.com/?p=131</guid>
		<description><![CDATA[Doing good image resizing in your favourite software development environment shouldn't be hard. After all, lots and lots of software that has a graphical user interface of some kind needs to do image resizing. However, in java it isn't as easy to do as it should be. I had some resizing needs, more specifically I [...]]]></description>
			<content:encoded><![CDATA[<p>Doing good image resizing in your favourite software development environment shouldn't be hard. After all, lots and lots of software that has a graphical user interface of some kind needs to do image resizing. However, in java it isn't as easy to do as it should be. I had some resizing needs, more specifically I needed code to resize a large black-and-white image into thumbnail size.</p>
<p>After googling a bit I came up with a <a href="http://java.sun.com/products/java-media/2D/reference/faqs/index.html#Q_How_do_I_create_a_resized_copy">recipe</a> from the official Java 2D FAQ at sun.com and used that. After all, the creators of Java should know how to do it right. However, I was surprised to find out that the visual result of the resizing was terrible. Have a look for yourself:</p>
<p><img class="size-full wp-image-132 alignnone" title="A black and white letter a, 310 pixels wide" src="http://noa.resare.com/wp-content/uploads/2008/12/mono.png" alt="A black and white letter a, 310 pixels wide" width="310" height="374" /></p>
<p>I started out with this letter a in black and white. When resizing that one to a version 40 pixels wide with the code that sun suggests, it looks like this when magnified:</p>
<p><img class="alignnone size-full wp-image-133" title="resize_bilinear_sun_blowup" src="http://noa.resare.com/wp-content/uploads/2008/12/resize_bilinear_sun_blowup.png" alt="resize_bilinear_sun_blowup" width="322" height="386" /></p>
<p>As you see, there is some grayscale smoothing going on but not much and the overall impression is quite jagged. Before anyone asks, yes I'm using the bilinear interpolation option. Compared to the result when resizing in GIMP, ImageMagick or just about any other tool the result is terrible. So i tried around, googled and looked at code here and there.</p>
<p>I was on my way to accept that java just didn't do this, and restort to calling a command line tool from my web application when I found a <a href="http://www.java2s.com/Code/Java/2D-Graphics-GUI/ScaleTest.htm">piece of code</a> that compares the speed and results of different scaling methods. It turns out that if you use the getScaledInstance() method of the java.awt.Image base class with the Image.SCALE_SMOOTH as last parameter, the result looks much better.</p>
<p>Here is a blown up version of a 40 pixels wide rescaling using that method instead:</p>
<p><img class="alignnone size-full wp-image-134" title="resize_scaledinstance_blowup" src="http://noa.resare.com/wp-content/uploads/2008/12/resize_scaledinstance_blowup.png" alt="resize_scaledinstance_blowup" width="322" height="386" /></p>
<p>Ah, much better. Why is this? I don't know. If there is anyone out there that can give me details on why this is I'm more than happy to be educated.</p>
<p>So, if you want to copy my method, please have a look at <a href="http://resare.com/noa/ref/ImageResizer.java">ImageResizer.java</a>. The version calling a verbatim copy of the suggested solution from Sun's FAQ is in the method sunResize() and the better looking version is in resize().</p>
]]></content:encoded>
			<wfw:commentRss>http://noa.resare.com/2008/12/image-resizing-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
