title: jpg images in iphone and 2x images
body: <p>I am working on an iphone app and  targeting <strong>iOS 4.0</strong> or later.  I am trying to add an image to UIImageView, and image is in <strong>jpeg format</strong>. This is what I have done so far..</p>
  
  <pre><code>UIImageView *bgImageView            =   [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 246.0)];
  bgImageView.image                   =   [UIImage imageNamed:@"background"];
  [self.view addSubview:bgImageView];
  [bgImageView release];
  </code></pre>
  
  <p>I have added two  images, </p>
  
  <ol>
  <li>background.jpg (as normal 1x image)</li>
  <li>background@2x.jpg (for 2x / retina
  display).</li>
  </ol>
  
  <p>But when I build and run, everything runs fine, except there is no background. All my other widgets are there, but there is a white background and image is not showing. </p>
  
  <p>Next I created two png images for my background, added it to the project and ran. This time my background was shown. I was perplexed because according to <a href="http://developer.apple.com/library/ios/#documentation/uikit/reference/UIImage_Class/Reference/Reference.html">documentation</a> jpg image can be used in iphone with UIImage.</p>
  
  <p>I tried again with my jpg images and changed the code  above to this</p>
  
  <pre><code>UIImageView *bgImageView            =   [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 246.0)];
  bgImageView.image                   =   [UIImage imageNamed:@"background.jpg"]; //added extension
  [self.view addSubview:bgImageView];
  [bgImageView release];
  </code></pre>
  
  <p>When I run the above code, background image is showing, but 2x images are not loaded. That shows my jpg image is fine, and it is not the culprit. So when I just give image name without extension, png files (both 1x and 2x)are loaded on respective devices, jpg files are not loaded at all. 
  Looks like a bug (either in sdk or documentation). iOS 4 is here for a good year. why no one noticed it? Also is there any option for me other than to convert all my images to png? </p>
  
  <p><strong>EDIT :</strong> </p>
  
  <p>Well, two days in to the question, zero answers. I have already converted all my images to png, and that part of my project is done (as my project couldn't wait..). Still, for my own sake and for sake of everyone who faces this in future, I would like to know more about this problem. At least someone can confirm that this is indeed an apple bug. I am starting a bounty so that more people can see this thread. </p>
  
  <p><strong>EDIT AGAIN</strong></p>
  
  <p>2 days remaining for this bounty to end. Thanks for everyone who responded. But let me clarify one thing. I have already said that I have converted all my images to png and I moved along.  I just wanted some confirmation that <code>imageNamed</code> treats jpg and png files same way. Documentation certainly says it will(unless Apple has written it somewhere other than <code>UIImage</code> documentation). If documentation is correct then my code failed me because of two possible reasons</p>
  
  <ol>
  <li><strong>It is a bug in</strong> <code>imageNamed</code>. If this is the reason, then I dont have too much option other than file a bug report, change my images to png or write a wrapper(like Chandan has said in his answer) and move on..</li>
  <li><strong>There is some problem with the jpeg image I used</strong>. Well I am not a photoshop guy. But I used 
  RGBA jpg image. If image does matter I am ready to ask my designer
  friend and provide more info.</li>
  </ol>
  
  <p>One more thing. <a href="http://www.oogtech.org/content/tag/imagenamed/">This</a> post also just tells about this problem. But he dont know the reason behind. So I am not alone.</p>
  
  <p><strong>EDIT : THE END</strong></p>
  
  <p>Well it is something related to the image itself. I googled and downloaded some sample jpeg images and played with it. Some of them shown up correctly and some doesn't. Since the boundy time is up, I am giving the boundy to PengOne who tried to reproduce the bug and successfully loaded jpg image without extension, there by making me to work with more images. Thanks for everyone who tried to help.</p>