<?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: Download, Create and Display an Image from URL</title>
	<atom:link href="http://iPhoneDeveloperTips.com/cocoa/download-and-create-an-image-from-a-url.html/feed" rel="self" type="application/rss+xml" />
	<link>http://iPhoneDeveloperTips.com/cocoa/download-and-create-an-image-from-a-url.html</link>
	<description>iOS Developer Tips, Tricks and Tutorials.</description>
	<lastBuildDate>Wed, 08 Feb 2012 06:31:16 -0600</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: HockeyBias.com</title>
		<link>http://iPhoneDeveloperTips.com/cocoa/download-and-create-an-image-from-a-url.html#comment-60626</link>
		<dc:creator>HockeyBias.com</dc:creator>
		<pubDate>Tue, 27 Sep 2011 19:01:39 +0000</pubDate>
		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=4476#comment-60626</guid>
		<description>Thanks!</description>
		<content:encoded><![CDATA[<p>Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: book</title>
		<link>http://iPhoneDeveloperTips.com/cocoa/download-and-create-an-image-from-a-url.html#comment-7061</link>
		<dc:creator>book</dc:creator>
		<pubDate>Wed, 25 Nov 2009 07:08:01 +0000</pubDate>
		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=4476#comment-7061</guid>
		<description>thanks</description>
		<content:encoded><![CDATA[<p>thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Muchow</title>
		<link>http://iPhoneDeveloperTips.com/cocoa/download-and-create-an-image-from-a-url.html#comment-6257</link>
		<dc:creator>John Muchow</dc:creator>
		<pubDate>Wed, 04 Nov 2009 13:34:53 +0000</pubDate>
		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=4476#comment-6257</guid>
		<description>Paul / Adrian,

Good call on the background thread...in cases such as this, I typically request the synchronous code to run in a new thread, something similar to the following:

&lt;pre lang=&quot;objc&quot;&gt;
- (void) loadImageInBackground
{
  NSURL *url = [NSURL URLWithString: 
     @&quot;http://iphonedevelopertips.com/images/logo-iphone-dev-tips.png&quot;];
     
  // Assume image is an instance variable
  image = [[UIImage imageWithData: [NSData dataWithContentsOfURL:url]] retain];
}

...

[NSThread detachNewThreadSelector:@selector(loadImageInBackground)
   toTarget:self withObject:nil];

...

[self.view addSubview:[[UIImageView alloc] initWithImage:image]];
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Paul / Adrian,</p>
<p>Good call on the background thread&#8230;in cases such as this, I typically request the synchronous code to run in a new thread, something similar to the following:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> loadImageInBackground
<span style="color: #002200;">&#123;</span>
  <span style="color: #400080;">NSURL</span> <span style="color: #002200;">*</span>url <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSURL</span> URLWithString<span style="color: #002200;">:</span> 
     <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;http://iphonedevelopertips.com/images/logo-iphone-dev-tips.png&quot;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
  <span style="color: #11740a; font-style: italic;">// Assume image is an instance variable</span>
  image <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIImage imageWithData<span style="color: #002200;">:</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSData</span> dataWithContentsOfURL<span style="color: #002200;">:</span>url<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span> retain<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
...
&nbsp;
<span style="color: #002200;">&#91;</span><span style="color: #400080;">NSThread</span> detachNewThreadSelector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>loadImageInBackground<span style="color: #002200;">&#41;</span>
   toTarget<span style="color: #002200;">:</span>self withObject<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
&nbsp;
...
&nbsp;
<span style="color: #002200;">&#91;</span>self.view addSubview<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIImageView alloc<span style="color: #002200;">&#93;</span> initWithImage<span style="color: #002200;">:</span>image<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

]]></content:encoded>
	</item>
	<item>
		<title>By: Adrian</title>
		<link>http://iPhoneDeveloperTips.com/cocoa/download-and-create-an-image-from-a-url.html#comment-6255</link>
		<dc:creator>Adrian</dc:creator>
		<pubDate>Wed, 04 Nov 2009 12:06:33 +0000</pubDate>
		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=4476#comment-6255</guid>
		<description>The problem with this approach is that this will block the UI thread until the image is downloaded. I would suggest using EGOImageLoading by Enormego for example http://url.akosma.com/sz9xb which loads the image in a background thread, and even caches it so that later it&#039;s retrieved from the local disk.</description>
		<content:encoded><![CDATA[<p>The problem with this approach is that this will block the UI thread until the image is downloaded. I would suggest using EGOImageLoading by Enormego for example <a href="http://url.akosma.com/sz9xb" rel="nofollow">http://url.akosma.com/sz9xb</a> which loads the image in a background thread, and even caches it so that later it&#8217;s retrieved from the local disk.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul Westbrook</title>
		<link>http://iPhoneDeveloperTips.com/cocoa/download-and-create-an-image-from-a-url.html#comment-6252</link>
		<dc:creator>Paul Westbrook</dc:creator>
		<pubDate>Wed, 04 Nov 2009 10:51:10 +0000</pubDate>
		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=4476#comment-6252</guid>
		<description>The problem this code is that the fetch happens synchronously.  If this is called in the UI thread, the app will appear block while the image is being fetched.

The fetch should happen on a background thread.</description>
		<content:encoded><![CDATA[<p>The problem this code is that the fetch happens synchronously.  If this is called in the UI thread, the app will appear block while the image is being fetched.</p>
<p>The fetch should happen on a background thread.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

