<?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>Misfiring Neurons &#187; thumbnail</title>
	<atom:link href="http://pavel.tcholakov.net/tag/thumbnail/feed/" rel="self" type="application/rss+xml" />
	<link>http://pavel.tcholakov.net</link>
	<description>Just another geek with a blog</description>
	<lastBuildDate>Sat, 28 Aug 2010 12:14:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Quick and easy image resizing with Java ImageIO</title>
		<link>http://pavel.tcholakov.net/2008/12/quick-and-easy-image-resizing-with-java-imageio/</link>
		<comments>http://pavel.tcholakov.net/2008/12/quick-and-easy-image-resizing-with-java-imageio/#comments</comments>
		<pubDate>Fri, 26 Dec 2008 17:28:07 +0000</pubDate>
		<dc:creator>Pavel</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[imageio]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jpeg]]></category>
		<category><![CDATA[jpg]]></category>
		<category><![CDATA[resize]]></category>
		<category><![CDATA[servlet]]></category>
		<category><![CDATA[thumbnail]]></category>

		<guid isPermaLink="false">http://kay.za.net/?p=120</guid>
		<description><![CDATA[There are quite a lot of examples of image resizing floating around the web but they all seem to access all sort of hidden features and classes deep inside the JDK to achieve their goal. Here is the most straightforward method that I could come up with - all in all just 5 lines of [...]]]></description>
			<content:encoded><![CDATA[<p>There are quite a lot of examples of image resizing floating around the web but they all seem to access all sort of hidden features and classes deep inside the JDK to achieve their goal. Here is the most straightforward method that I could come up with - all in all just 5 lines of code. It requires ImageIO and requires Java 1.4 or later to run. If the ImageIO.write() method accepted plain ol' AWT Image arguments it could have been reduced further still to three lines, but you have to give it a BufferedImage instance as input.</p>
<p>The snippet below assumes that there exist the following variables (coloured <span style="color: #339966;">green</span> in the code):</p>
<ul>
<li>an input stream to read from</li>
<li>a desired width variable (specifying the height as -1 tells the toolkit to preserve the original aspect ratio)</li>
<li>and an output stream to write the encoded image to.</li>
</ul>
<p>Sample code:</p>
<pre style="padding-left: 30px;"><strong><span style="color: #000080;">import </span></strong>java.awt.Image;
<strong><span style="color: #000080;">import </span></strong>java.awt.image.BufferedImage;
<strong><span style="color: #000080;">import </span></strong>javax.imageio.ImageIO;</pre>
<pre style="padding-left: 30px;">// ...

BufferedImage sourceImage = ImageIO.<em>read</em>(<span style="color: #339966;">inputStream</span>);
Image thumbnail = sourceImage.getScaledInstance(<span style="color: #339966;">width</span>, <span style="color: #0000ff;">-1</span>, Image.<em><span style="color: #800080;">SCALE_SMOOTH</span></em>);
BufferedImage bufferedThumbnail = <strong><span style="color: #333399;">new </span></strong>BufferedImage(thumbnail.getWidth(<span style="color: #333399;"><strong>null</strong></span>),
                                                    thumbnail.getHeight(<strong><span style="color: #333399;">null</span></strong>),
                                                    BufferedImage.<em><span style="color: #800080;">TYPE_INT_RGB</span></em>);
bufferedThumbnail.getGraphics().drawImage(thumbnail, <span style="color: #0000ff;">0</span>, <span style="color: #0000ff;">0</span>, <strong><span style="color: #333399;">null</span></strong>);
ImageIO.<em>write</em>(bufferedThumbnail, <span style="color: #0000ff;">"jpeg"</span>, <span style="color: #339966;">outputStream</span>);</pre>
]]></content:encoded>
			<wfw:commentRss>http://pavel.tcholakov.net/2008/12/quick-and-easy-image-resizing-with-java-imageio/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
