<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Flyingdogz&#039;s Weblog &#187; image</title>
	<atom:link href="http://flyingdogz.wordpress.com/tag/image/feed/" rel="self" type="application/rss+xml" />
	<link>http://flyingdogz.wordpress.com</link>
	<description>Me Myself and My way</description>
	<lastBuildDate>Sat, 05 Dec 2009 11:16:31 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='flyingdogz.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/fe8948f776c7bb020c81267bb6258866?s=96&#038;d=http://s2.wp.com/i/buttonw-com.png</url>
		<title>Flyingdogz&#039;s Weblog &#187; image</title>
		<link>http://flyingdogz.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://flyingdogz.wordpress.com/osd.xml" title="Flyingdogz&#039;s Weblog" />
	<atom:link rel='hub' href='http://flyingdogz.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Image Rotate in Java #2 : easier to use</title>
		<link>http://flyingdogz.wordpress.com/2008/02/11/image-rotate-in-java-2-easier-to-use/</link>
		<comments>http://flyingdogz.wordpress.com/2008/02/11/image-rotate-in-java-2-easier-to-use/#comments</comments>
		<pubDate>Sun, 10 Feb 2008 19:37:38 +0000</pubDate>
		<dc:creator>flyingdogz</dc:creator>
				<category><![CDATA[Computer]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[rotate]]></category>

		<guid isPermaLink="false">http://flyingdogz.wordpress.com/?p=49</guid>
		<description><![CDATA[I&#8217;ve combine the source I provided in the first article , which receive and return BufferedImage object , with the Image to a BufferedImage code that I&#8217;ve found from  http://www.exampledepot.com/egs/java.awt.image/Image2Buf.html.
The result is the Class ImageUtils with the rotateImage() method that receive 2 parameters , img &#8211; an Image object to rotate and degree &#8211; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=flyingdogz.wordpress.com&blog=1783545&post=49&subd=flyingdogz&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve combine the source I provided in <a href="http://flyingdogz.wordpress.com/2008/02/09/image-rotate-in-java/">the first article</a> , which receive and return BufferedImage object , with the Image to a BufferedImage code that I&#8217;ve found from  <a href="http://www.exampledepot.com/egs/java.awt.image/Image2Buf.html" target="_blank">http://www.exampledepot.com/egs/java.awt.image/Image2Buf.html</a>.</p>
<p>The result is the Class ImageUtils with the rotateImage() method that receive 2 parameters , img &#8211; an Image object to rotate and degree &#8211; the integer value of the degree that img will be rotated, the code is all shown below <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p>** please note that I&#8217;m ONLY just combine these code to make it easier to use and I DIDN&#8217;T wrote it all myself.</p>
<p>ImageUtils.java</p>
<pre>
package mystic.utils;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.HeadlessException;
import java.awt.Image;
import java.awt.Transparency;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.PixelGrabber;
import javax.swing.ImageIcon;

public class ImageUtils {

    public static Image rotateImage(Image img,double degree){
        BufferedImage bufImg = toBufferedImage(img);
        double angle = Math.toRadians(degree);

        return tilt(bufImg,angle);
    }

    public static BufferedImage tilt(BufferedImage image, double angle) {
        double sin = Math.abs(Math.sin(angle)), cos = Math.abs(Math.cos(angle));
        int w = image.getWidth(), h = image.getHeight();
        int neww = (int)Math.floor(w*cos+h*sin), newh = (int)Math.floor(h*cos+w*sin);
        GraphicsConfiguration gc = getDefaultConfiguration();
        BufferedImage result = gc.createCompatibleImage(neww, newh, Transparency.TRANSLUCENT);
        Graphics2D g = result.createGraphics();
        g.translate((neww-w)/2, (newh-h)/2);
        g.rotate(angle, w/2, h/2);
        g.drawRenderedImage(image, null);
        g.dispose();
        return result;
    }

    public static GraphicsConfiguration getDefaultConfiguration() {
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice gd = ge.getDefaultScreenDevice();
        return gd.getDefaultConfiguration();
    }

    // http://www.exampledepot.com/egs/java.awt.image/Image2Buf.html
    // An Image object cannot be converted to a BufferedImage object.
    // The closest equivalent is to create a buffered image and then draw the image on the buffered image.
    // This example defines a method that does this.

    // This method returns a buffered image with the contents of an image
    public static BufferedImage toBufferedImage(Image image) {
        if (image instanceof BufferedImage) {
            return (BufferedImage)image;
        }

        // This code ensures that all the pixels in the image are loaded
        image = new ImageIcon(image).getImage();

        // Determine if the image has transparent pixels; for this method's
        // implementation, see e661 Determining If an Image Has Transparent Pixels
        boolean hasAlpha = hasAlpha(image);

        // Create a buffered image with a format that's compatible with the screen
        BufferedImage bimage = null;
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        try {
            // Determine the type of transparency of the new buffered image
            int transparency = Transparency.OPAQUE;
            if (hasAlpha) {
                transparency = Transparency.BITMASK;
            }

            // Create the buffered image
            GraphicsDevice gs = ge.getDefaultScreenDevice();
            GraphicsConfiguration gc = gs.getDefaultConfiguration();
            bimage = gc.createCompatibleImage(
                image.getWidth(null), image.getHeight(null), transparency);
        } catch (HeadlessException e) {
            // The system does not have a screen
        }

        if (bimage == null) {
            // Create a buffered image using the default color model
            int type = BufferedImage.TYPE_INT_RGB;
            if (hasAlpha) {
                type = BufferedImage.TYPE_INT_ARGB;
            }
            bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), type);
        }

        // Copy image to buffered image
        Graphics g = bimage.createGraphics();

        // Paint the image onto the buffered image
        g.drawImage(image, 0, 0, null);
        g.dispose();

        return bimage;
    }

    // http://www.exampledepot.com/egs/java.awt.image/HasAlpha.html
    // This method returns true if the specified image has transparent pixels
    public static boolean hasAlpha(Image image) {
        // If buffered image, the color model is readily available
        if (image instanceof BufferedImage) {
            BufferedImage bimage = (BufferedImage)image;
            return bimage.getColorModel().hasAlpha();
        }

        // Use a pixel grabber to retrieve the image's color model;
        // grabbing a single pixel is usually sufficient
         PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false);
        try {
            pg.grabPixels();
        } catch (InterruptedException e) {
        }

        // Get the image's color model
        ColorModel cm = pg.getColorModel();
        return cm.hasAlpha();
    }
}</pre>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/flyingdogz.wordpress.com/49/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/flyingdogz.wordpress.com/49/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/flyingdogz.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/flyingdogz.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/flyingdogz.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/flyingdogz.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/flyingdogz.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/flyingdogz.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/flyingdogz.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/flyingdogz.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/flyingdogz.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/flyingdogz.wordpress.com/49/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=flyingdogz.wordpress.com&blog=1783545&post=49&subd=flyingdogz&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://flyingdogz.wordpress.com/2008/02/11/image-rotate-in-java-2-easier-to-use/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5fe720d1b5e7055c62cc16969e8829b3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">flyingdogz</media:title>
		</media:content>
	</item>
		<item>
		<title>Image Rotate in Java</title>
		<link>http://flyingdogz.wordpress.com/2008/02/09/image-rotate-in-java/</link>
		<comments>http://flyingdogz.wordpress.com/2008/02/09/image-rotate-in-java/#comments</comments>
		<pubDate>Fri, 08 Feb 2008 22:49:40 +0000</pubDate>
		<dc:creator>flyingdogz</dc:creator>
				<category><![CDATA[Computer]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[rotate]]></category>

		<guid isPermaLink="false">http://flyingdogz.wordpress.com/?p=36</guid>
		<description><![CDATA[Source : http://forum.java.sun.com/thread.jspa?threadID=487900&#38;messageID=2286191


import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import java.net.*;
import javax.imageio.*;
import javax.swing.*;

public class Tilt {
    public static void main(String[] args) throws IOException {
        URL url = new URL("http://weblogs.java.net/jag/Image1-large.jpeg");
        final BufferedImage image = ImageIO.read(url);
        [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=flyingdogz.wordpress.com&blog=1783545&post=36&subd=flyingdogz&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class="pad5x10">Source : http://forum.java.sun.com/thread.jspa?threadID=487900&amp;messageID=2286191</div>
<div class="pad5x10"></div>
<div class="pad5x10">
<pre><code><font color="navy"><b>import</b></font> java.awt.*;
<font color="navy"><b>import</b></font> java.awt.event.*;
<font color="navy"><b>import</b></font> java.awt.image.*;
<font color="navy"><b>import</b></font> java.io.*;
<font color="navy"><b>import</b></font> java.net.*;
<font color="navy"><b>import</b></font> javax.imageio.*;
<font color="navy"><b>import</b></font> javax.swing.*;

<font color="navy"><b>public</b></font> <font color="navy"><b>class</b></font> Tilt <font color="navy">{</font>
    <font color="navy"><b>public</b></font> <font color="navy"><b>static</b></font> <font color="navy"><b>void</b></font> main(String[] args) <font color="navy"><b>throws</b></font> IOException <font color="navy">{</font>
        URL url = <font color="navy"><b>new</b></font> URL(<font color="red">"http://weblogs.java.net/jag/Image1-large.jpeg"</font>);
        <font color="navy"><b>final</b></font> BufferedImage image = ImageIO.read(url);
        <font color="navy"><b>final</b></font> JLabel label = <font color="navy"><b>new</b></font> JLabel(<font color="navy"><b>new</b></font> ImageIcon(image));
        <font color="navy"><b>new</b></font> Timer(100, <font color="navy"><b>new</b></font> ActionListener()<font color="navy">{</font>
            <font color="navy"><b>double</b></font> angle = 0;
            <font color="navy"><b>public</b></font> <font color="navy"><b>void</b></font> actionPerformed(ActionEvent evt) <font color="navy">{</font>
                angle += Math.PI/50;
                label.setIcon(<font color="navy"><b>new</b></font> ImageIcon(tilt(image, angle)));
            <font color="navy">}</font>
        <font color="navy">}</font>).start();
        JFrame f = <font color="navy"><b>new</b></font> JFrame(<font color="red">"TILT"</font>);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.getContentPane().add(label);
        f.setSize(400,400);
        f.setLocationRelativeTo(<font color="navy"><b>null</b></font>);
        f.setVisible(<font color="navy"><b>true</b></font>);
    <font color="navy">}</font>

    <font color="navy"><b>public</b></font> <font color="navy"><b>static</b></font> BufferedImage tilt(BufferedImage image, <font color="navy"><b>double</b></font> angle) <font color="navy">{</font>
        <font color="navy"><b>double</b></font> sin = Math.abs(Math.sin(angle)), cos = Math.abs(Math.cos(angle));
        <font color="navy"><b>int</b></font> w = image.getWidth(), h = image.getHeight();
        <font color="navy"><b>int</b></font> neww = (<font color="navy"><b>int</b></font>)Math.floor(w*cos+h*sin), newh = (<font color="navy"><b>int</b></font>)Math.floor(h*cos+w*sin);
        GraphicsConfiguration gc = getDefaultConfiguration();
        BufferedImage result = gc.createCompatibleImage(neww, newh, Transparency.TRANSLUCENT);
        Graphics2D g = result.createGraphics();
        g.translate((neww-w)/2, (newh-h)/2);
        g.rotate(angle, w/2, h/2);
        g.drawRenderedImage(image, <font color="navy"><b>null</b></font>);
        g.dispose();
        <font color="navy"><b>return</b></font> result;
    <font color="navy">}</font>

    <font color="navy"><b>public</b></font> <font color="navy"><b>static</b></font> GraphicsConfiguration getDefaultConfiguration() <font color="navy">{</font>
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice gd = ge.getDefaultScreenDevice();
        <font color="navy"><b>return</b></font> gd.getDefaultConfiguration();
    <font color="navy">}</font>
<font color="navy">}</font> </code></pre>
</div>
<div class="pad5x10"></div>
<div class="pad5x10">you can also try a getRotateInstance (double, int, int) too. (from comment in that thread)</div>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/flyingdogz.wordpress.com/36/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/flyingdogz.wordpress.com/36/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/flyingdogz.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/flyingdogz.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/flyingdogz.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/flyingdogz.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/flyingdogz.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/flyingdogz.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/flyingdogz.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/flyingdogz.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/flyingdogz.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/flyingdogz.wordpress.com/36/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=flyingdogz.wordpress.com&blog=1783545&post=36&subd=flyingdogz&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://flyingdogz.wordpress.com/2008/02/09/image-rotate-in-java/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5fe720d1b5e7055c62cc16969e8829b3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">flyingdogz</media:title>
		</media:content>
	</item>
	</channel>
</rss>