<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: ratio code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sat, 17 May 2008 22:55:16 GMT</pubDate>
    <description>DZone Snippets: ratio code</description>
    <item>
      <title>C#: Resize An Image While Maintaining Aspect Ratio and Maximum Height</title>
      <link>http://snippets.dzone.com/posts/show/4336</link>
      <description>// This allows us to resize the image. It prevents skewed images and &lt;br /&gt;// also vertically long images caused by trying to maintain the aspect &lt;br /&gt;// ratio on images who's height is larger than their width&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;public void ResizeImage(string OriginalFile, string NewFile, int NewWidth, int MaxHeight, bool OnlyResizeIfWider)&lt;br /&gt;{&lt;br /&gt;	System.Drawing.Image FullsizeImage = System.Drawing.Image.FromFile(OriginalFile);&lt;br /&gt;&lt;br /&gt;	// Prevent using images internal thumbnail&lt;br /&gt;	FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);&lt;br /&gt;	FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);&lt;br /&gt;&lt;br /&gt;	if (OnlyResizeIfWider)&lt;br /&gt;	{&lt;br /&gt;		if (FullsizeImage.Width &lt;= NewWidth)&lt;br /&gt;		{&lt;br /&gt;			NewWidth = FullsizeImage.Width;&lt;br /&gt;		}&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;	int NewHeight = FullsizeImage.Height * NewWidth / FullsizeImage.Width;&lt;br /&gt;	if (NewHeight &gt; MaxHeight)&lt;br /&gt;	{&lt;br /&gt;		// Resize with height instead&lt;br /&gt;		NewWidth = FullsizeImage.Width * MaxHeight / FullsizeImage.Height;&lt;br /&gt;		NewHeight = MaxHeight;&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;	System.Drawing.Image NewImage = FullsizeImage.GetThumbnailImage(NewWidth, NewHeight, null, IntPtr.Zero);&lt;br /&gt;&lt;br /&gt;	// Clear handle to original file so that we can overwrite it if necessary&lt;br /&gt;	FullsizeImage.Dispose();&lt;br /&gt;&lt;br /&gt;	// Save resized picture&lt;br /&gt;	NewImage.Save(NewFile);&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 19 Jul 2007 22:55:39 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4336</guid>
      <author>cornerblue (CornerBLUE, Inc.)</author>
    </item>
    <item>
      <title>Convert a number to its closest fraction</title>
      <link>http://snippets.dzone.com/posts/show/741</link>
      <description>Sometimes, I need to find a ratio approximation of a number.&lt;br /&gt;Like 640 / 480 (vga) or similar number. I learn about farey&lt;br /&gt;series a few years ago (1994). &lt;br /&gt;The &lt;a href=http://en.wikipedia.org/wiki/Farey_sequence&gt;idea&lt;/a&gt; is actually quite simple.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&gt;&gt;&gt; farey(math.pi,100)&lt;br /&gt;(22, 7)&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Get the implementation &lt;a href=http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52317&gt;here&lt;/a&gt;.</description>
      <pubDate>Sun, 18 Sep 2005 15:08:27 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/741</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
  </channel>
</rss>
