<?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>Powertips &#187; UIImage</title>
	<atom:link href="http://scripting.chaindb.com/category/ios/uiimage/feed/" rel="self" type="application/rss+xml" />
	<link>http://scripting.chaindb.com</link>
	<description>Programmer tips</description>
	<lastBuildDate>Tue, 15 May 2012 23:56:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>How to get new image size in UIImageView</title>
		<link>http://scripting.chaindb.com/2012/04/09/how-to-get-new-image-size-in-uiimageview/</link>
		<comments>http://scripting.chaindb.com/2012/04/09/how-to-get-new-image-size-in-uiimageview/#comments</comments>
		<pubDate>Mon, 09 Apr 2012 14:59:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[iOS]]></category>
		<category><![CDATA[UIImage]]></category>
		<category><![CDATA[UIImageView]]></category>

		<guid isPermaLink="false">http://scripting.chaindb.com/?p=1215</guid>
		<description><![CDATA[Sometime we need to know the new size of the image that’s being rendered in UIImageView with auto scaled applied. Here’s the computation -(CGRect)frameForImage:(UIImage*)image inImageViewAspectFit:(UIImageView*)imageView { float imageRatio = image.size.width / image.size.height; float viewRatio = imageView.frame.size.width / imageView.frame.size.height; if(imageRatio < viewRatio) { float scale = imageView.frame.size.height / image.size.height; float width = scale * image.size.width; float [...]]]></description>
			<content:encoded><![CDATA[<p><script type="text/javascript"><!--
google_ad_client = "pub-7360303176440694";
/* scripting_468x15, created 5/12/10 */
google_ad_slot = "3352621531";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><br />
Sometime we need to know the new size of the image that’s being rendered in UIImageView with auto scaled applied. Here’s the computation</p>
<p>-(CGRect)frameForImage:(UIImage*)image inImageViewAspectFit:(UIImageView*)imageView<br />
{<br />
    float imageRatio = image.size.width / image.size.height;</p>
<p>    float viewRatio = imageView.frame.size.width / imageView.frame.size.height;</p>
<p>    if(imageRatio < viewRatio)<br />
    {<br />
        float scale = imageView.frame.size.height / image.size.height;</p>
<p>        float width = scale * image.size.width;</p>
<p>        float topLeftX = (imageView.frame.size.width - width) * 0.5;</p>
<p>        return CGRectMake(topLeftX, 0, width, imageView.frame.size.height);<br />
    }<br />
    else<br />
    {<br />
        float scale = imageView.frame.size.width / image.size.width;</p>
<p>        float height = scale * image.size.height;</p>
<p>        float topLeftY = (imageView.frame.size.height - height) * 0.5;</p>
<p>        return CGRectMake(0, topLeftY, imageView.frame.size.width, height);<br />
    }</p>
<p>}</p>
<p><a href="http://stackoverflow.com/questions/389342/how-to-get-the-size-of-a-scaled-uiimage-in-uiimageview" title="Source" target="_blank">Source</a><br />
<script type="text/javascript"><!--
google_ad_client = "pub-7360303176440694";
/* scripting_Banner (468 x 60) */
google_ad_slot = "0537236933";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://scripting.chaindb.com/2012/04/09/how-to-get-new-image-size-in-uiimageview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to save UIImage to application document in IOS</title>
		<link>http://scripting.chaindb.com/2012/03/10/how-to-save-uiimage-to-application-document-in-ios/</link>
		<comments>http://scripting.chaindb.com/2012/03/10/how-to-save-uiimage-to-application-document-in-ios/#comments</comments>
		<pubDate>Fri, 09 Mar 2012 16:09:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[iOS]]></category>
		<category><![CDATA[UIImage]]></category>
		<category><![CDATA[nsdata]]></category>
		<category><![CDATA[save]]></category>

		<guid isPermaLink="false">http://scripting.chaindb.com/?p=1180</guid>
		<description><![CDATA[Here&#8217;s a sample snippet on how to save image to application document. var infolink_pid = 307811; var infolink_wsid = 0; - &#40;void&#41;saveUIImage:&#40;UIImage *&#41;image withName:&#40;NSString *&#41;name &#123; NSData *imgData = UIImageJPEGRepresentation&#40;image, 1.0&#41;; NSFileManager *fileManager = &#91;NSFileManager defaultManager&#93;; NSArray *paths = NSSearchPathForDirectoriesInDomains&#40;NSDocumentDirectory, NSUserDomainMask, &#160;YES&#41;; NSString *documentsDirectory = &#91;paths objectAtIndex:0&#93;; NSString *fullPath = &#91;documentsDirectory stringByAppendingPathComponent:name&#93;; &#91;fileManager createFileAtPath:fullPath contents:imgData [...]]]></description>
			<content:encoded><![CDATA[<p><script type="text/javascript"><!--
google_ad_client = "pub-7360303176440694";
/* scripting_Banner (468 x 60) */
google_ad_slot = "0537236933";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><br />
Here&#8217;s a sample snippet on how to save image to application document.<br />
<script type="text/javascript">
    var infolink_pid = 307811;
    var infolink_wsid = 0;
</script>
<script type="text/javascript" src="http://resources.infolinks.com/js/infolinks_main.js"></script></p>
<div class="geshi no vbnet">
<ol>
<li class="li1">
<div class="de1"><span class="sy0">-</span> <span class="br0">&#40;</span>void<span class="br0">&#41;</span>saveUIImage:<span class="br0">&#40;</span>UIImage <span class="sy0">*</span><span class="br0">&#41;</span>image withName:<span class="br0">&#40;</span>NSString <span class="sy0">*</span><span class="br0">&#41;</span>name <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">NSData <span class="sy0">*</span>imgData <span class="sy0">=</span> UIImageJPEGRepresentation<span class="br0">&#40;</span>image, <span class="nu0">1.0</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">NSFileManager <span class="sy0">*</span>fileManager <span class="sy0">=</span> <span class="br0">&#91;</span>NSFileManager defaultManager<span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1">NSArray <span class="sy0">*</span>paths <span class="sy0">=</span> NSSearchPathForDirectoriesInDomains<span class="br0">&#40;</span>NSDocumentDirectory, NSUserDomainMask, &nbsp;<span class="kw1">YES</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">NSString <span class="sy0">*</span>documentsDirectory <span class="sy0">=</span> <span class="br0">&#91;</span>paths objectAtIndex:<span class="nu0">0</span><span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1">NSString <span class="sy0">*</span>fullPath <span class="sy0">=</span> <span class="br0">&#91;</span>documentsDirectory stringByAppendingPathComponent:name<span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>fileManager createFileAtPath:fullPath contents:imgData attributes:nil<span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://scripting.chaindb.com/2012/03/10/how-to-save-uiimage-to-application-document-in-ios/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to flip UIImage</title>
		<link>http://scripting.chaindb.com/2011/08/07/how-to-flip-uiimage/</link>
		<comments>http://scripting.chaindb.com/2011/08/07/how-to-flip-uiimage/#comments</comments>
		<pubDate>Sun, 07 Aug 2011 13:04:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[UIImage]]></category>
		<category><![CDATA[Flip]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">http://scripting.chaindb.com/?p=1011</guid>
		<description><![CDATA[UIImage* sourceImage = [UIImage imageNamed:@"whatever.png"];  UIImage* flippedImage = [UIImage imageWithCGImage:sourceImage.CGImage scale:1.0 orientation: UIImageOrientationUpMirrored]; Constants: UIImageOrientation Specifies the possible orientations of an image. typedef enum { UIImageOrientationUp, UIImageOrientationDown, // 180 deg rotation UIImageOrientationLeft, // 90 deg CCW UIImageOrientationRight, // 90 deg CW UIImageOrientationUpMirrored, // as above but image mirrored along // other axis. horizontal flip UIImageOrientationDownMirrored, [...]]]></description>
			<content:encoded><![CDATA[<pre><code>UIImage* sourceImage = [UIImage imageNamed:@"whatever.png"]; </code></pre>
<pre><code>UIImage* flippedImage = [UIImage imageWithCGImage:sourceImage.CGImage scale:1.0 orientation: UIImageOrientationUpMirrored];</code></pre>
<pre><code>Constants:</code></pre>
<h3>UIImageOrientation</h3>
<p>Specifies the possible orientations of an image.</p>
<pre>typedef enum {
   <a href="http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIImage_Class/Reference/Reference.html#//apple_ref/doc/c_ref/UIImageOrientationUp">UIImageOrientationUp</a>,
   <a href="http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIImage_Class/Reference/Reference.html#//apple_ref/doc/c_ref/UIImageOrientationDown">UIImageOrientationDown</a>,   // 180 deg rotation
   <a href="http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIImage_Class/Reference/Reference.html#//apple_ref/doc/c_ref/UIImageOrientationLeft">UIImageOrientationLeft</a>,   // 90 deg CCW
   <a href="http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIImage_Class/Reference/Reference.html#//apple_ref/doc/c_ref/UIImageOrientationRight">UIImageOrientationRight</a>,   // 90 deg CW
   <a href="http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIImage_Class/Reference/Reference.html#//apple_ref/doc/c_ref/UIImageOrientationUpMirrored">UIImageOrientationUpMirrored</a>,    // as above but image mirrored along
   // other axis. horizontal flip
   <a href="http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIImage_Class/Reference/Reference.html#//apple_ref/doc/c_ref/UIImageOrientationDownMirrored">UIImageOrientationDownMirrored</a>,  // horizontal flip
   <a href="http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIImage_Class/Reference/Reference.html#//apple_ref/doc/c_ref/UIImageOrientationLeftMirrored">UIImageOrientationLeftMirrored</a>,  // vertical flip
   <a href="http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIImage_Class/Reference/Reference.html#//apple_ref/doc/c_ref/UIImageOrientationRightMirrored">UIImageOrientationRightMirrored</a>, // vertical flip
} UIImageOrientation;</pre>
<pre><a title="UIImage" href="http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIImage_Class/Reference/Reference.html" target="_blank">Read More</a> at ios developer reference</pre>
<pre><code>
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://scripting.chaindb.com/2011/08/07/how-to-flip-uiimage/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

