<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: iPhone development &#8211; UIImage with round corners</title>
	<atom:link href="http://blog.sallarp.com/iphone-uiimage-round-corners/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sallarp.com/iphone-uiimage-round-corners/</link>
	<description>Code, Code, Revolution!</description>
	<lastBuildDate>Tue, 09 Mar 2010 21:04:19 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Cole</title>
		<link>http://blog.sallarp.com/iphone-uiimage-round-corners/comment-page-1/#comment-7309</link>
		<dc:creator>Cole</dc:creator>
		<pubDate>Fri, 29 Jan 2010 22:02:21 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sallarp.com/?p=58#comment-7309</guid>
		<description>The analyzer is still going to think the image is a zombie, so return the image passed in:

+(UIImage *)makeRoundCornerImage : (UIImage*) img : (int) cornerWidth : (int) cornerHeight
{
	UIImage * newImage = nil;
	
	if( nil != img) {
		NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
		int w = img.size.width;
		int h = img.size.height;
    
		CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
		CGContextRef context = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, colorSpace, kCGImageAlphaPremultipliedFirst);
    
		CGContextBeginPath(context);
		CGRect rect = CGRectMake(0, 0, img.size.width, img.size.height);
		addRoundedRectToPath(context, rect, cornerWidth, cornerHeight);
		CGContextClosePath(context);
		CGContextClip(context);
    
		CGContextDrawImage(context, CGRectMake(0, 0, w, h), img.CGImage);
    
		CGImageRef imageMasked = CGBitmapContextCreateImage(context);
		CGContextRelease(context);
		CGColorSpaceRelease(colorSpace);
	
		newImage = [[UIImage imageWithCGImage:imageMasked] retain];
		CGImageRelease(imageMasked);
		img = newImage;
		[newImage release];
		[pool release];
	}
	return img;
}

@end</description>
		<content:encoded><![CDATA[<p>The analyzer is still going to think the image is a zombie, so return the image passed in:</p>
<p>+(UIImage *)makeRoundCornerImage : (UIImage*) img : (int) cornerWidth : (int) cornerHeight<br />
{<br />
	UIImage * newImage = nil;</p>
<p>	if( nil != img) {<br />
		NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];<br />
		int w = img.size.width;<br />
		int h = img.size.height;</p>
<p>		CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();<br />
		CGContextRef context = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, colorSpace, kCGImageAlphaPremultipliedFirst);</p>
<p>		CGContextBeginPath(context);<br />
		CGRect rect = CGRectMake(0, 0, img.size.width, img.size.height);<br />
		addRoundedRectToPath(context, rect, cornerWidth, cornerHeight);<br />
		CGContextClosePath(context);<br />
		CGContextClip(context);</p>
<p>		CGContextDrawImage(context, CGRectMake(0, 0, w, h), img.CGImage);</p>
<p>		CGImageRef imageMasked = CGBitmapContextCreateImage(context);<br />
		CGContextRelease(context);<br />
		CGColorSpaceRelease(colorSpace);</p>
<p>		newImage = [[UIImage imageWithCGImage:imageMasked] retain];<br />
		CGImageRelease(imageMasked);<br />
		img = newImage;<br />
		[newImage release];<br />
		[pool release];<br />
	}<br />
	return img;<br />
}</p>
<p>@end</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sabes</title>
		<link>http://blog.sallarp.com/iphone-uiimage-round-corners/comment-page-1/#comment-6286</link>
		<dc:creator>sabes</dc:creator>
		<pubDate>Wed, 09 Dec 2009 04:07:29 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sallarp.com/?p=58#comment-6286</guid>
		<description>super easy:

#import 

appIconImage.image = [UIImage imageWithContentsOfFile:@&quot;image.png&quot;]; 
appIconImage.layer.masksToBounds = YES;
appIconImage.layer.cornerRadius = 10.0;
appIconImage.layer.borderWidth = 1.0;
appIconImage.layer.borderColor = [[UIColor grayColor] CGColor];</description>
		<content:encoded><![CDATA[<p>super easy:</p>
<p>#import </p>
<p>appIconImage.image = [UIImage imageWithContentsOfFile:@"image.png"];<br />
appIconImage.layer.masksToBounds = YES;<br />
appIconImage.layer.cornerRadius = 10.0;<br />
appIconImage.layer.borderWidth = 1.0;<br />
appIconImage.layer.borderColor = [[UIColor grayColor] CGColor];</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joe</title>
		<link>http://blog.sallarp.com/iphone-uiimage-round-corners/comment-page-1/#comment-5787</link>
		<dc:creator>Joe</dc:creator>
		<pubDate>Sat, 21 Nov 2009 03:14:35 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sallarp.com/?p=58#comment-5787</guid>
		<description>OK, next best thing … but you need to be using Joe Hewitt&#039;s Three20 library. (I know, cheating, right? Ahh well.) This example gives your TTImageView rounded corners. I gather you could also chain another style at the end to get the border.

i.backgroundColor = [UIColor clearColor];
i.style = [TTShapeStyle styleWithShape:[TTRoundedRectangleShape shapeWithTopLeft:10 topRight:10 bottomRight:10 bottomLeft:10] next:[TTContentStyle styleWithNext:nil]];</description>
		<content:encoded><![CDATA[<p>OK, next best thing … but you need to be using Joe Hewitt&#8217;s Three20 library. (I know, cheating, right? Ahh well.) This example gives your TTImageView rounded corners. I gather you could also chain another style at the end to get the border.</p>
<p>i.backgroundColor = [UIColor clearColor];<br />
i.style = [TTShapeStyle styleWithShape:[TTRoundedRectangleShape shapeWithTopLeft:10 topRight:10 bottomRight:10 bottomLeft:10] next:[TTContentStyle styleWithNext:nil]];</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joe</title>
		<link>http://blog.sallarp.com/iphone-uiimage-round-corners/comment-page-1/#comment-5786</link>
		<dc:creator>Joe</dc:creator>
		<pubDate>Sat, 21 Nov 2009 02:58:08 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sallarp.com/?p=58#comment-5786</guid>
		<description>Of course, messing with the CALayer of a UIImageView might not be such a good idea after all. (Try scrolling with one of these image views inside.) Hmm. Well, maybe there&#039;s a happy medium that&#039;s just as minimal, code-wise, but still gets what we want in short order (?).</description>
		<content:encoded><![CDATA[<p>Of course, messing with the CALayer of a UIImageView might not be such a good idea after all. (Try scrolling with one of these image views inside.) Hmm. Well, maybe there&#8217;s a happy medium that&#8217;s just as minimal, code-wise, but still gets what we want in short order (?).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joe</title>
		<link>http://blog.sallarp.com/iphone-uiimage-round-corners/comment-page-1/#comment-5784</link>
		<dc:creator>Joe</dc:creator>
		<pubDate>Sat, 21 Nov 2009 02:38:20 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sallarp.com/?p=58#comment-5784</guid>
		<description>Here&#039;s another way to handle it using a UIImageView (into which you place said image) … and (drum roll) layers!

  #import 
  ...
  // Add a corner radius:
  CALayer *l = [myImageView layer];
  l.masksToBounds = YES;
  l.cornerRadius = 10.0;
  l.borderWidth = 1.0;
  l.borderColor = [[UIColor darkGrayColor] CGColor];

I kid you not. Works like a charm.

Be sure to include the QuartzCore framework, as well as the header up top in your implementation file.</description>
		<content:encoded><![CDATA[<p>Here&#8217;s another way to handle it using a UIImageView (into which you place said image) … and (drum roll) layers!</p>
<p>  #import<br />
  &#8230;<br />
  // Add a corner radius:<br />
  CALayer *l = [myImageView layer];<br />
  l.masksToBounds = YES;<br />
  l.cornerRadius = 10.0;<br />
  l.borderWidth = 1.0;<br />
  l.borderColor = [[UIColor darkGrayColor] CGColor];</p>
<p>I kid you not. Works like a charm.</p>
<p>Be sure to include the QuartzCore framework, as well as the header up top in your implementation file.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: DEV&#187; Blog Archive &#187; Drowning in NSAutoreleasePool</title>
		<link>http://blog.sallarp.com/iphone-uiimage-round-corners/comment-page-1/#comment-5641</link>
		<dc:creator>DEV&#187; Blog Archive &#187; Drowning in NSAutoreleasePool</dc:creator>
		<pubDate>Sat, 14 Nov 2009 01:59:00 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sallarp.com/?p=58#comment-5641</guid>
		<description>[...] An example of this technique can be found on Björn Sållarp&#8217;s article &#8220;UIImage with round corners&#8221;: http://blog.sallarp.com/iphone-uiimage-round-corners [...]</description>
		<content:encoded><![CDATA[<p>[...] An example of this technique can be found on Björn Sållarp&#8217;s article &#8220;UIImage with round corners&#8221;: <a href="http://blog.sallarp.com/iphone-uiimage-round-corners">http://blog.sallarp.com/iphone-uiimage-round-corners</a> [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stephen</title>
		<link>http://blog.sallarp.com/iphone-uiimage-round-corners/comment-page-1/#comment-5464</link>
		<dc:creator>Stephen</dc:creator>
		<pubDate>Sat, 07 Nov 2009 19:31:20 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sallarp.com/?p=58#comment-5464</guid>
		<description>I thought this code was great but does it work with a number of images? I have an image for each cell on my tableview. When I open the view the images are all rounded nicely but when I scroll the app crashes.</description>
		<content:encoded><![CDATA[<p>I thought this code was great but does it work with a number of images? I have an image for each cell on my tableview. When I open the view the images are all rounded nicely but when I scroll the app crashes.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: DJ</title>
		<link>http://blog.sallarp.com/iphone-uiimage-round-corners/comment-page-1/#comment-4594</link>
		<dc:creator>DJ</dc:creator>
		<pubDate>Fri, 16 Oct 2009 15:39:45 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sallarp.com/?p=58#comment-4594</guid>
		<description>Fantastic work!  How would you go about rounding off just one corner?  E.g. for an imageview in a groupedstyle tableview.</description>
		<content:encoded><![CDATA[<p>Fantastic work!  How would you go about rounding off just one corner?  E.g. for an imageview in a groupedstyle tableview.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Resize a UIImage the right way &#8212; Trevor&#8217;s Bike Shed</title>
		<link>http://blog.sallarp.com/iphone-uiimage-round-corners/comment-page-1/#comment-4536</link>
		<dc:creator>Resize a UIImage the right way &#8212; Trevor&#8217;s Bike Shed</dc:creator>
		<pubDate>Tue, 13 Oct 2009 07:01:52 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sallarp.com/?p=58#comment-4536</guid>
		<description>[...] Creates a copy of the image, adding rounded corners of the specified radius. If borderSize is non-zero, a transparent border of the given size will also be added. (The primary purpose of this parameter is to work around the aforementioned aliasing problem that occurs when rotating an image view.) The implementation is based on code by Björn Sållarp. [...]</description>
		<content:encoded><![CDATA[<p>[...] Creates a copy of the image, adding rounded corners of the specified radius. If borderSize is non-zero, a transparent border of the given size will also be added. (The primary purpose of this parameter is to work around the aforementioned aliasing problem that occurs when rotating an image view.) The implementation is based on code by Björn Sållarp. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Guy Umbright</title>
		<link>http://blog.sallarp.com/iphone-uiimage-round-corners/comment-page-1/#comment-4259</link>
		<dc:creator>Guy Umbright</dc:creator>
		<pubDate>Tue, 29 Sep 2009 15:10:37 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sallarp.com/?p=58#comment-4259</guid>
		<description>I will second what Michael said, nice work, but that release of the passed in image has to go.  Just spent a while tracking down how my image became a zombie.</description>
		<content:encoded><![CDATA[<p>I will second what Michael said, nice work, but that release of the passed in image has to go.  Just spent a while tracking down how my image became a zombie.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
