﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-Pudgy's World-文章分类-Computer</title><link>http://www.blogjava.net/Pudgy/category/2630.html</link><description>&lt;SCRIPT&gt;
var dict_width   = 'auto'
var dict_height  = '72px'
var dict_background = 'transparent'
var dict_border  = '0px dotted #000000'
var dict_textColor = '#6FBC4C'
var dict_fontSize = '100%'
var dict_encoding = 'Utf-8'
&lt;/SCRIPT&gt;
&lt;SCRIPT src="http://livid.cn/services/fortune"&gt;&lt;/SCRIPT&gt;
&lt;script src="http://www.google-analytics.com/urchin.js" type="text/javascript"&gt;
&lt;/script&gt;</description><language>zh-cn</language><lastBuildDate>Wed, 28 Feb 2007 15:41:24 GMT</lastBuildDate><pubDate>Wed, 28 Feb 2007 15:41:24 GMT</pubDate><ttl>60</ttl><item><title>Rotate Class</title><link>http://www.blogjava.net/Pudgy/articles/13703.html</link><dc:creator>Pudgy's World</dc:creator><author>Pudgy's World</author><pubDate>Wed, 21 Sep 2005 23:26:00 GMT</pubDate><guid>http://www.blogjava.net/Pudgy/articles/13703.html</guid><wfw:comment>http://www.blogjava.net/Pudgy/comments/13703.html</wfw:comment><comments>http://www.blogjava.net/Pudgy/articles/13703.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Pudgy/comments/commentRss/13703.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Pudgy/services/trackbacks/13703.html</trackback:ping><description><![CDATA[<P> </P>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #000000">    </SPAN><SPAN style="COLOR: #008000">/**</SPAN><SPAN style="COLOR: #008000"><BR>     * Constant to specify that the bounding box should be not be changed <BR>     * for any angle of rotation when creating the rotated image.  This <BR>     * means the returned image will be the same size as the given image.  <BR>     * Of course, that also means the corners of the image may be cut off.  <BR>     </SPAN><SPAN style="COLOR: #008000">*/</SPAN><SPAN style="COLOR: #000000"><BR>    </SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">static</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">final</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000"> NO_BOUNDING_BOX </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">;<BR> <BR>    </SPAN><SPAN style="COLOR: #008000">/**</SPAN><SPAN style="COLOR: #008000"><BR>     * Constant to specify that the exact bounding box should be used for <BR>     * the specified angle of rotation when creating the rotated image.  <BR>     * This is the default option.  When used, the rotated image may be <BR>     * larger then the source image, but no larger then needed to fit the <BR>     * rotated image exactly.  Therefore, rotating the same image to various <BR>     * angles may result in varying image sizes.  <BR>     </SPAN><SPAN style="COLOR: #008000">*/</SPAN><SPAN style="COLOR: #000000"><BR>    </SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">static</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">final</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000"> EXACT_BOUNDING_BOX </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">;<BR> <BR>    </SPAN><SPAN style="COLOR: #008000">/**</SPAN><SPAN style="COLOR: #008000"><BR>     * Constant to specify that the largest bounding box should be used when <BR>     * creating the rotated image.  When used, the rotated image will be <BR>     * larger then the source image, but all rotated images of that same <BR>     * source image will be the same size, regardless of the angle of <BR>     * rotation.  This may result in significant "empty space" between the <BR>     * edge of the returned image and the actual drawn pixel areas.  <BR>     </SPAN><SPAN style="COLOR: #008000">*/</SPAN><SPAN style="COLOR: #000000"><BR>    </SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">static</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">final</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000"> LARGEST_BOUNDING_BOX </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">2</SPAN><SPAN style="COLOR: #000000">;<BR><BR><BR>    </SPAN><SPAN style="COLOR: #008000">/**</SPAN><SPAN style="COLOR: #008000"><BR>     * Rotates the specified image the specified number of degrees.  The <BR>     * rotation is performed around the center point of the image.  <BR>     * <BR>     * </SPAN><SPAN style="COLOR: #808080">@param</SPAN><SPAN style="COLOR: #008000">  img         the image to rotate<BR>     * </SPAN><SPAN style="COLOR: #808080">@param</SPAN><SPAN style="COLOR: #008000">  degrees     the degrees to rotate<BR>     * </SPAN><SPAN style="COLOR: #808080">@param</SPAN><SPAN style="COLOR: #008000">  bbm         the bounding box mode, default is EXACT_BOUNDING_BOX<BR>     * </SPAN><SPAN style="COLOR: #808080">@param</SPAN><SPAN style="COLOR: #008000">  background  the background paint (texture, color or gradient), <BR>     *                     can be null<BR>     * </SPAN><SPAN style="COLOR: #808080">@return</SPAN><SPAN style="COLOR: #008000">  the image<BR>     * </SPAN><SPAN style="COLOR: #808080">@see</SPAN><SPAN style="COLOR: #008000">  #NO_BOUNDING_BOX<BR>     * </SPAN><SPAN style="COLOR: #808080">@see</SPAN><SPAN style="COLOR: #008000">  #EXACT_BOUNDING_BOX<BR>     * </SPAN><SPAN style="COLOR: #808080">@see</SPAN><SPAN style="COLOR: #008000">  #LARGEST_BOUNDING_BOX<BR>     </SPAN><SPAN style="COLOR: #008000">*/</SPAN><SPAN style="COLOR: #000000"><BR>    </SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">static</SPAN><SPAN style="COLOR: #000000"> BufferedImage rotateDegrees(Image img, </SPAN><SPAN style="COLOR: #0000ff">double</SPAN><SPAN style="COLOR: #000000"> degrees, </SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000"> bbm, Paint background) {<BR>        </SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000"> rotateRadians(img, Math.toRadians(degrees), bbm, background);<BR>    }<BR> <BR>    </SPAN><SPAN style="COLOR: #008000">/**</SPAN><SPAN style="COLOR: #008000"><BR>     * Rotates the specified image the specified number of radians.  The <BR>     * rotation is performed around the center point of the image.  This <BR>     * method is provided for convenience of applications using radians.  <BR>     * For most people, degrees is simpler to use.  <BR>     * <BR>     * </SPAN><SPAN style="COLOR: #808080">@param</SPAN><SPAN style="COLOR: #008000">  img         the image to rotate<BR>     * </SPAN><SPAN style="COLOR: #808080">@param</SPAN><SPAN style="COLOR: #008000">  radians     the radians to rotate<BR>     * </SPAN><SPAN style="COLOR: #808080">@param</SPAN><SPAN style="COLOR: #008000">  bbm         the bounding box mode, default is EXACT_BOUNDING_BOX<BR>     * </SPAN><SPAN style="COLOR: #808080">@param</SPAN><SPAN style="COLOR: #008000">  background  the background paint (texture, color or gradient), <BR>     *                     can be null<BR>     * </SPAN><SPAN style="COLOR: #808080">@return</SPAN><SPAN style="COLOR: #008000">  the image<BR>     * </SPAN><SPAN style="COLOR: #808080">@see</SPAN><SPAN style="COLOR: #008000">  #NO_BOUNDING_BOX<BR>     * </SPAN><SPAN style="COLOR: #808080">@see</SPAN><SPAN style="COLOR: #008000">  #EXACT_BOUNDING_BOX<BR>     * </SPAN><SPAN style="COLOR: #808080">@see</SPAN><SPAN style="COLOR: #008000">  #LARGEST_BOUNDING_BOX<BR>     </SPAN><SPAN style="COLOR: #008000">*/</SPAN><SPAN style="COLOR: #000000"><BR>    </SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">static</SPAN><SPAN style="COLOR: #000000"> BufferedImage rotateRadians(Image img, </SPAN><SPAN style="COLOR: #0000ff">double</SPAN><SPAN style="COLOR: #000000"> radians, </SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000"> bbm, Paint background) {<BR>        </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> get the original image's width and height</SPAN><SPAN style="COLOR: #008000"><BR></SPAN><SPAN style="COLOR: #000000">        </SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000"> iw </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> img.getWidth(</SPAN><SPAN style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #000000">);<BR>        </SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000"> ih </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> img.getHeight(</SPAN><SPAN style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #000000">);<BR>        </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> calculate the new image's size based on bounding box mode</SPAN><SPAN style="COLOR: #008000"><BR></SPAN><SPAN style="COLOR: #000000">        Dimension dim;<BR>        </SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">(bbm </SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000"> NO_BOUNDING_BOX) {<BR>            dim </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> Dimension(iw, ih);<BR>        } </SPAN><SPAN style="COLOR: #0000ff">else</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">(bbm </SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000"> LARGEST_BOUNDING_BOX) {<BR>            dim </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> getLargestBoundingBox(iw, ih);<BR>        } </SPAN><SPAN style="COLOR: #0000ff">else</SPAN><SPAN style="COLOR: #000000"> { </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> EXACT_BOUNDING_BOX</SPAN><SPAN style="COLOR: #008000"><BR></SPAN><SPAN style="COLOR: #000000">            dim </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> getBoundingBox(iw, ih, Math.toDegrees(radians));<BR>        }<BR>        </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> get the new image's width and height</SPAN><SPAN style="COLOR: #008000"><BR></SPAN><SPAN style="COLOR: #000000">        </SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000"> w </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> dim.width;<BR>        </SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000"> h </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> dim.height;<BR>        </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> get the location to draw the original image on the new image</SPAN><SPAN style="COLOR: #008000"><BR></SPAN><SPAN style="COLOR: #000000">        </SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000"> x </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> (w</SPAN><SPAN style="COLOR: #000000">/</SPAN><SPAN style="COLOR: #000000">2</SPAN><SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">(iw</SPAN><SPAN style="COLOR: #000000">/</SPAN><SPAN style="COLOR: #000000">2</SPAN><SPAN style="COLOR: #000000">);<BR>        </SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000"> y </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> (h</SPAN><SPAN style="COLOR: #000000">/</SPAN><SPAN style="COLOR: #000000">2</SPAN><SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">(ih</SPAN><SPAN style="COLOR: #000000">/</SPAN><SPAN style="COLOR: #000000">2</SPAN><SPAN style="COLOR: #000000">);<BR>        </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> need to copy the given image to a new BufferedImage because <BR>        </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> it is, in most cases, going to be a larger image so it <BR>        </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> needs to be drawn centered on the larger image</SPAN><SPAN style="COLOR: #008000"><BR></SPAN><SPAN style="COLOR: #000000">        BufferedImage bi </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);<BR>        Graphics2D g2d </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> bi.createGraphics();<BR>        </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> set some rendering hints for better looking images</SPAN><SPAN style="COLOR: #008000"><BR></SPAN><SPAN style="COLOR: #000000">        g2d.setRenderingHints(renderingHints);<BR>        </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> draw the background paint, if necessary</SPAN><SPAN style="COLOR: #008000"><BR></SPAN><SPAN style="COLOR: #000000">        </SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">(background </SPAN><SPAN style="COLOR: #000000">!=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #000000">) {<BR>            g2d.setPaint(background);<BR>            g2d.fillRect(</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">, </SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">, w, h);<BR>        }<BR>        </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> if not rotating, just draw it normally, else create a transform</SPAN><SPAN style="COLOR: #008000"><BR></SPAN><SPAN style="COLOR: #000000">        </SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">(radians </SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">0.0</SPAN><SPAN style="COLOR: #000000">) {<BR>            g2d.drawImage(img, x, y, iw, ih, </SPAN><SPAN style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #000000">);<BR>        } </SPAN><SPAN style="COLOR: #0000ff">else</SPAN><SPAN style="COLOR: #000000"> {<BR>            g2d.rotate(radians, w</SPAN><SPAN style="COLOR: #000000">/</SPAN><SPAN style="COLOR: #000000">2</SPAN><SPAN style="COLOR: #000000">, h</SPAN><SPAN style="COLOR: #000000">/</SPAN><SPAN style="COLOR: #000000">2</SPAN><SPAN style="COLOR: #000000">);<BR>            g2d.translate(x, y);<BR>            g2d.drawImage(img, </SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">, </SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">, iw, ih, </SPAN><SPAN style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #000000">);<BR>        }<BR>        g2d.dispose();<BR>        </SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000"> bi;<BR>    }<BR> <BR>    </SPAN><SPAN style="COLOR: #008000">/**</SPAN><SPAN style="COLOR: #008000"><BR>     * Gets the largest bounding box size that can hold an image of the <BR>     * specified size at any angle of rotation.  <BR>     * <BR>     * </SPAN><SPAN style="COLOR: #808080">@param</SPAN><SPAN style="COLOR: #008000">  width   the image width<BR>     * </SPAN><SPAN style="COLOR: #808080">@param</SPAN><SPAN style="COLOR: #008000">  height  the image height<BR>     * </SPAN><SPAN style="COLOR: #808080">@return</SPAN><SPAN style="COLOR: #008000">  the bounding box size<BR>     </SPAN><SPAN style="COLOR: #008000">*/</SPAN><SPAN style="COLOR: #000000"><BR>    </SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">static</SPAN><SPAN style="COLOR: #000000"> Dimension getLargestBoundingBox(</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000"> width, </SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000"> height) {<BR>        </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> The largest bounding box is the largest area needed to fit the <BR>        </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> specified image at any angle or rotation.  This is simpler then <BR>        </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> getting the bounding box for a given angle because the largest <BR>        </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> box will put the corner of the image box directly along the <BR>        </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> vertical or horizontal axis from the image center point.  The <BR>        </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> distance between the image rectangle's center and any corner <BR>        </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> is the hypotenuse of a right triangle who's other sides are <BR>        </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> half the width (a) and half the height (b) of the rectangle.  <BR>        </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> A little a^2 + b^2 = c^2 calculation and we get the length of <BR>        </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> the hypotenuse.  Double that to get a square within which the <BR>        </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> image can be rotated at any angle without clipping the image.  </SPAN><SPAN style="COLOR: #008000"><BR></SPAN><SPAN style="COLOR: #000000">        </SPAN><SPAN style="COLOR: #0000ff">double</SPAN><SPAN style="COLOR: #000000"> a </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> (</SPAN><SPAN style="COLOR: #0000ff">double</SPAN><SPAN style="COLOR: #000000">)width </SPAN><SPAN style="COLOR: #000000">/</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">2.0</SPAN><SPAN style="COLOR: #000000">;<BR>        </SPAN><SPAN style="COLOR: #0000ff">double</SPAN><SPAN style="COLOR: #000000"> b </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> (</SPAN><SPAN style="COLOR: #0000ff">double</SPAN><SPAN style="COLOR: #000000">)height </SPAN><SPAN style="COLOR: #000000">/</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">2.0</SPAN><SPAN style="COLOR: #000000">;<BR>        </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> use Math.ceil() to round up to an int value</SPAN><SPAN style="COLOR: #008000"><BR></SPAN><SPAN style="COLOR: #000000">        </SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000"> c </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> (</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">)Math.ceil(Math.sqrt((a </SPAN><SPAN style="COLOR: #000000">*</SPAN><SPAN style="COLOR: #000000"> a) </SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000"> (b </SPAN><SPAN style="COLOR: #000000">*</SPAN><SPAN style="COLOR: #000000"> b)) </SPAN><SPAN style="COLOR: #000000">*</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">2.0</SPAN><SPAN style="COLOR: #000000">);<BR>        </SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> Dimension(c, c);<BR>    }<BR> <BR>    </SPAN><SPAN style="COLOR: #008000">/**</SPAN><SPAN style="COLOR: #008000"><BR>     * Gets the optimal/smallest bounding box size that can hold an image of <BR>     * the specified size at the specified angle of rotation.  <BR>     * <BR>     * </SPAN><SPAN style="COLOR: #808080">@param</SPAN><SPAN style="COLOR: #008000">  width   the image width<BR>     * </SPAN><SPAN style="COLOR: #808080">@param</SPAN><SPAN style="COLOR: #008000">  height  the image height<BR>     * </SPAN><SPAN style="COLOR: #808080">@return</SPAN><SPAN style="COLOR: #008000">  the bounding box size<BR>     </SPAN><SPAN style="COLOR: #008000">*/</SPAN><SPAN style="COLOR: #000000"><BR>    </SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">static</SPAN><SPAN style="COLOR: #000000"> Dimension getBoundingBox(</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000"> width, </SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000"> height, </SPAN><SPAN style="COLOR: #0000ff">double</SPAN><SPAN style="COLOR: #000000"> degrees) {<BR>        degrees </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> normalizeDegrees(degrees);<BR>        </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> if no rotation or 180 degrees, the size won't change</SPAN><SPAN style="COLOR: #008000"><BR></SPAN><SPAN style="COLOR: #000000">        </SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">(degrees </SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">0.0</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">||</SPAN><SPAN style="COLOR: #000000"> degrees </SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">180.0</SPAN><SPAN style="COLOR: #000000">) {<BR>            </SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> Dimension(width, height);<BR>        }<BR>        </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> if 90 or 270 (quarter or 3-quarter rotations) the width becomes <BR>        </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> the height, and vice versa</SPAN><SPAN style="COLOR: #008000"><BR></SPAN><SPAN style="COLOR: #000000">        </SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">(degrees </SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">90.0</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">||</SPAN><SPAN style="COLOR: #000000"> degrees </SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">270.0</SPAN><SPAN style="COLOR: #000000">) {<BR>            </SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> Dimension(height, width);<BR>        }<BR>        </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> for any other rotation, we need to do some trigonometry, <BR>        </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> derived from description found at:  <BR>        </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> </SPAN><SPAN style="COLOR: #008000; TEXT-DECORATION: underline">http://www.codeproject.com/csharp/rotateimage.asp</SPAN><SPAN style="COLOR: #008000"><BR></SPAN><SPAN style="COLOR: #000000">        </SPAN><SPAN style="COLOR: #0000ff">double</SPAN><SPAN style="COLOR: #000000"> radians </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> Math.toRadians(degrees);<BR>        </SPAN><SPAN style="COLOR: #0000ff">double</SPAN><SPAN style="COLOR: #000000"> aW </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> Math.abs(Math.cos(radians) </SPAN><SPAN style="COLOR: #000000">*</SPAN><SPAN style="COLOR: #000000"> width);<BR>        </SPAN><SPAN style="COLOR: #0000ff">double</SPAN><SPAN style="COLOR: #000000"> oW </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> Math.abs(Math.sin(radians) </SPAN><SPAN style="COLOR: #000000">*</SPAN><SPAN style="COLOR: #000000"> width);<BR>        </SPAN><SPAN style="COLOR: #0000ff">double</SPAN><SPAN style="COLOR: #000000"> aH </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> Math.abs(Math.cos(radians) </SPAN><SPAN style="COLOR: #000000">*</SPAN><SPAN style="COLOR: #000000"> height);<BR>        </SPAN><SPAN style="COLOR: #0000ff">double</SPAN><SPAN style="COLOR: #000000"> oH </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> Math.abs(Math.sin(radians) </SPAN><SPAN style="COLOR: #000000">*</SPAN><SPAN style="COLOR: #000000"> height);<BR>        </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> use Math.ceil() to round up to an int value</SPAN><SPAN style="COLOR: #008000"><BR></SPAN><SPAN style="COLOR: #000000">        </SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000"> w </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> (</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">)Math.ceil(aW </SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000"> oH);<BR>        </SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000"> h </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> (</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">)Math.ceil(oW </SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000"> aH);<BR>        </SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> Dimension(w, h);<BR>    }</SPAN></DIV><img src ="http://www.blogjava.net/Pudgy/aggbug/13703.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Pudgy/" target="_blank">Pudgy's World</a> 2005-09-22 07:26 <a href="http://www.blogjava.net/Pudgy/articles/13703.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Rotate Image 45 Degrees</title><link>http://www.blogjava.net/Pudgy/articles/13702.html</link><dc:creator>Pudgy's World</dc:creator><author>Pudgy's World</author><pubDate>Wed, 21 Sep 2005 23:23:00 GMT</pubDate><guid>http://www.blogjava.net/Pudgy/articles/13702.html</guid><wfw:comment>http://www.blogjava.net/Pudgy/comments/13702.html</wfw:comment><comments>http://www.blogjava.net/Pudgy/articles/13702.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Pudgy/comments/commentRss/13702.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Pudgy/services/trackbacks/13702.html</trackback:ping><description><![CDATA[<P><!--StartFragment --> <FONT size=+2>Rotate Image 45 Degrees</FONT> <BR></P>
<P> </P>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008000">/*</SPAN><SPAN style="COLOR: #008000"><BR><BR>Java Media APIs: Cross-Platform Imaging, Media and Visualization<BR>Alejandro Terrazas<BR>Sams, Published November 2002, <BR>ISBN 0672320940<BR></SPAN><SPAN style="COLOR: #008000">*/</SPAN><SPAN style="COLOR: #000000"><BR><BR><BR></SPAN><SPAN style="COLOR: #0000ff">import</SPAN><SPAN style="COLOR: #000000"> java.awt.Graphics;<BR></SPAN><SPAN style="COLOR: #0000ff">import</SPAN><SPAN style="COLOR: #000000"> java.awt.Graphics2D;<BR></SPAN><SPAN style="COLOR: #0000ff">import</SPAN><SPAN style="COLOR: #000000"> java.awt.Image;<BR></SPAN><SPAN style="COLOR: #0000ff">import</SPAN><SPAN style="COLOR: #000000"> java.awt.Insets;<BR></SPAN><SPAN style="COLOR: #0000ff">import</SPAN><SPAN style="COLOR: #000000"> java.awt.MediaTracker;<BR></SPAN><SPAN style="COLOR: #0000ff">import</SPAN><SPAN style="COLOR: #000000"> java.awt.Toolkit;<BR></SPAN><SPAN style="COLOR: #0000ff">import</SPAN><SPAN style="COLOR: #000000"> java.awt.geom.AffineTransform;<BR></SPAN><SPAN style="COLOR: #0000ff">import</SPAN><SPAN style="COLOR: #000000"> java.awt.geom.Point2D;<BR></SPAN><SPAN style="COLOR: #0000ff">import</SPAN><SPAN style="COLOR: #000000"> java.awt.image.AffineTransformOp;<BR></SPAN><SPAN style="COLOR: #0000ff">import</SPAN><SPAN style="COLOR: #000000"> java.awt.image.BufferedImage;<BR></SPAN><SPAN style="COLOR: #0000ff">import</SPAN><SPAN style="COLOR: #000000"> java.awt.image.BufferedImageOp;<BR><BR></SPAN><SPAN style="COLOR: #0000ff">import</SPAN><SPAN style="COLOR: #000000"> javax.swing.JFrame;<BR><BR></SPAN><SPAN style="COLOR: #008000">/**</SPAN><SPAN style="COLOR: #008000"><BR> * RotateImage45Degrees.java - 1. scales an image's dimensions by a factor of<BR> * two 2. rotates it 45 degrees around the image center 3. displays the<BR> * processed image<BR> </SPAN><SPAN style="COLOR: #008000">*/</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000"> RotateImage45Degrees </SPAN><SPAN style="COLOR: #0000ff">extends</SPAN><SPAN style="COLOR: #000000"> JFrame {<BR>  </SPAN><SPAN style="COLOR: #0000ff">private</SPAN><SPAN style="COLOR: #000000"> Image inputImage;<BR><BR>  </SPAN><SPAN style="COLOR: #0000ff">private</SPAN><SPAN style="COLOR: #000000"> BufferedImage sourceBI;<BR><BR>  </SPAN><SPAN style="COLOR: #0000ff">private</SPAN><SPAN style="COLOR: #000000"> BufferedImage destinationBI </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #000000">;<BR><BR>  </SPAN><SPAN style="COLOR: #0000ff">private</SPAN><SPAN style="COLOR: #000000"> Insets frameInsets;<BR><BR>  </SPAN><SPAN style="COLOR: #0000ff">private</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">boolean</SPAN><SPAN style="COLOR: #000000"> sizeSet </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">false</SPAN><SPAN style="COLOR: #000000">;<BR><BR>  </SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000"> RotateImage45Degrees(String imageFile) {<BR>    addNotify();<BR>    frameInsets </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> getInsets();<BR>    inputImage </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> Toolkit.getDefaultToolkit().getImage(imageFile);<BR><BR>    MediaTracker mt </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> MediaTracker(</SPAN><SPAN style="COLOR: #0000ff">this</SPAN><SPAN style="COLOR: #000000">);<BR>    mt.addImage(inputImage, </SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">);<BR>    </SPAN><SPAN style="COLOR: #0000ff">try</SPAN><SPAN style="COLOR: #000000"> {<BR>      mt.waitForID(</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">);<BR>    } </SPAN><SPAN style="COLOR: #0000ff">catch</SPAN><SPAN style="COLOR: #000000"> (InterruptedException ie) {<BR>    }<BR><BR>    sourceBI </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> BufferedImage(inputImage.getWidth(</SPAN><SPAN style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #000000">), inputImage<BR>        .getHeight(</SPAN><SPAN style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #000000">), BufferedImage.TYPE_INT_ARGB);<BR><BR>    Graphics2D g </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> (Graphics2D) sourceBI.getGraphics();<BR>    g.drawImage(inputImage, </SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">, </SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">, </SPAN><SPAN style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #000000">);<BR><BR>    AffineTransform at </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> AffineTransform();<BR><BR>    </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> scale image</SPAN><SPAN style="COLOR: #008000"><BR></SPAN><SPAN style="COLOR: #000000">    at.scale(</SPAN><SPAN style="COLOR: #000000">2.0</SPAN><SPAN style="COLOR: #000000">, </SPAN><SPAN style="COLOR: #000000">2.0</SPAN><SPAN style="COLOR: #000000">);<BR><BR>    </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> rotate 45 degrees around image center</SPAN><SPAN style="COLOR: #008000"><BR></SPAN><SPAN style="COLOR: #000000">    at.rotate(</SPAN><SPAN style="COLOR: #000000">45.0</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">*</SPAN><SPAN style="COLOR: #000000"> Math.PI </SPAN><SPAN style="COLOR: #000000">/</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">180.0</SPAN><SPAN style="COLOR: #000000">, sourceBI.getWidth() </SPAN><SPAN style="COLOR: #000000">/</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">2.0</SPAN><SPAN style="COLOR: #000000">, sourceBI<BR>        .getHeight() </SPAN><SPAN style="COLOR: #000000">/</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">2.0</SPAN><SPAN style="COLOR: #000000">);<BR><BR>    </SPAN><SPAN style="COLOR: #008000">/*</SPAN><SPAN style="COLOR: #008000"><BR>     * translate to make sure the rotation doesn't cut off any image data<BR>     </SPAN><SPAN style="COLOR: #008000">*/</SPAN><SPAN style="COLOR: #000000"><BR>    AffineTransform translationTransform;<BR>    translationTransform </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> findTranslation(at, sourceBI);<BR>    at.preConcatenate(translationTransform);<BR><BR>    </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> instantiate and apply affine transformation filter</SPAN><SPAN style="COLOR: #008000"><BR></SPAN><SPAN style="COLOR: #000000">    BufferedImageOp bio;<BR>    bio </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);<BR><BR>    destinationBI </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> bio.filter(sourceBI, </SPAN><SPAN style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #000000">);<BR><BR>    </SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000"> frameInsetsHorizontal </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> frameInsets.right </SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000"> frameInsets.left;<BR>    </SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000"> frameInsetsVertical </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> frameInsets.top </SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000"> frameInsets.bottom;<BR>    setSize(destinationBI.getWidth() </SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000"> frameInsetsHorizontal, destinationBI<BR>        .getHeight()<BR>        </SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000"> frameInsetsVertical);<BR>    show();<BR>  }<BR><BR>  </SPAN><SPAN style="COLOR: #008000">/*</SPAN><SPAN style="COLOR: #008000"><BR>   * find proper translations to keep rotated image correctly displayed<BR>   </SPAN><SPAN style="COLOR: #008000">*/</SPAN><SPAN style="COLOR: #000000"><BR>  </SPAN><SPAN style="COLOR: #0000ff">private</SPAN><SPAN style="COLOR: #000000"> AffineTransform findTranslation(AffineTransform at, BufferedImage bi) {<BR>    Point2D p2din, p2dout;<BR><BR>    p2din </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> Point2D.Double(</SPAN><SPAN style="COLOR: #000000">0.0</SPAN><SPAN style="COLOR: #000000">, </SPAN><SPAN style="COLOR: #000000">0.0</SPAN><SPAN style="COLOR: #000000">);<BR>    p2dout </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> at.transform(p2din, </SPAN><SPAN style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #000000">);<BR>    </SPAN><SPAN style="COLOR: #0000ff">double</SPAN><SPAN style="COLOR: #000000"> ytrans </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> p2dout.getY();<BR><BR>    p2din </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> Point2D.Double(</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">, bi.getHeight());<BR>    p2dout </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> at.transform(p2din, </SPAN><SPAN style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #000000">);<BR>    </SPAN><SPAN style="COLOR: #0000ff">double</SPAN><SPAN style="COLOR: #000000"> xtrans </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> p2dout.getX();<BR><BR>    AffineTransform tat </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> AffineTransform();<BR>    tat.translate(</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">xtrans, </SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">ytrans);<BR>    </SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000"> tat;<BR>  }<BR><BR>  </SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000"> paint(Graphics g) {<BR>    </SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000"> (destinationBI </SPAN><SPAN style="COLOR: #000000">!=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #000000">)<BR>      g.drawImage(destinationBI, frameInsets.left, frameInsets.top, </SPAN><SPAN style="COLOR: #0000ff">this</SPAN><SPAN style="COLOR: #000000">);<BR>  }<BR><BR>  </SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">static</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000"> main(String[] args) {<BR>    </SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> RotateImage45Degrees(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">fruits.png</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR>  }<BR><BR>}</SPAN></DIV>
<P><A href="http://www.blogjava.net/Pudgy/Pudgy/Pudgy/admin/EditArticles.aspx"></A> </P><img src ="http://www.blogjava.net/Pudgy/aggbug/13702.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Pudgy/" target="_blank">Pudgy's World</a> 2005-09-22 07:23 <a href="http://www.blogjava.net/Pudgy/articles/13702.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Hello, everyone!!</title><link>http://www.blogjava.net/Pudgy/articles/9622.html</link><dc:creator>Pudgy's World</dc:creator><author>Pudgy's World</author><pubDate>Mon, 08 Aug 2005 17:12:00 GMT</pubDate><guid>http://www.blogjava.net/Pudgy/articles/9622.html</guid><wfw:comment>http://www.blogjava.net/Pudgy/comments/9622.html</wfw:comment><comments>http://www.blogjava.net/Pudgy/articles/9622.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Pudgy/comments/commentRss/9622.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Pudgy/services/trackbacks/9622.html</trackback:ping><description><![CDATA[<P>Thanks</P><img src ="http://www.blogjava.net/Pudgy/aggbug/9622.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Pudgy/" target="_blank">Pudgy's World</a> 2005-08-09 01:12 <a href="http://www.blogjava.net/Pudgy/articles/9622.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>