Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6130573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:52:27+00:00 2026-05-23T16:52:27+00:00

I am working on an iphone app and targeting iOS 4.0 or later. I

  • 0

I am working on an iphone app and targeting iOS 4.0 or later. I am trying to add an image to UIImageView, and image is in jpeg format. This is what I have done so far..

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];

I have added two images,

  1. background.jpg (as normal 1x image)
  2. background@2x.jpg (for 2x / retina
    display).

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.

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 documentation jpg image can be used in iphone with UIImage.

I tried again with my jpg images and changed the code above to this

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];

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?

EDIT :

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.

EDIT AGAIN

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 imageNamed treats jpg and png files same way. Documentation certainly says it will(unless Apple has written it somewhere other than UIImage documentation). If documentation is correct then my code failed me because of two possible reasons

  1. It is a bug in imageNamed. 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..
  2. There is some problem with the jpeg image I used. 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.

One more thing. This post also just tells about this problem. But he dont know the reason behind. So I am not alone.

EDIT : THE END

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:52:27+00:00Added an answer on May 23, 2026 at 4:52 pm

    According to the UIImage Class Reference:

    Discussion

    This method looks in the system caches for an image object with the
    specified name and returns that object if it exists. If a matching
    image object is not already in the cache, this method loads the image
    data from the specified file, caches it, and then returns the
    resulting object.

    On a device running iOS 4 or later, the behavior is identical if the
    device’s screen has a scale of 1.0. If the screen has a scale of 2.0,
    this method first searches for an image file with the same filename
    with an @2x suffix appended to it. For example, if the file’s name is
    button, it first searches for button@2x. If it finds a 2x, it loads
    that image and sets the scale property of the returned UIImage object
    to 2.0. Otherwise, it loads the unmodified filename and sets the scale
    property to 1.0. See iOS Application Programming Guide for more
    information on supporting images with different scale factors. Special

    Considerations

    On iOS 4 and later, the name of the file is not required to specify
    the filename extension. Prior to iOS 4, you must specify the filename
    extension.

    Since you’re targeting iOS 4.0 and later, you should not need the filename extension. I tried to reproduce this potential bug, but it worked as expected for me without the filename extensions.

    Here are some ideas for what may have gone wrong to create this effect in your app:

    1. It’s possible that the problem comes from the cache if you changed your images at some point.

    2. If you choose not to use the filename extensions, and you have both “background.jpg” and “background.png” as options, the preference appears to be to use the “.png” file.

    3. If you set the target to iOS 4.0 and later after first running the app, then the filename extension would have been required and the image may have been cached blank, which leads back to theory 1.

    That’s the best I can make of this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working with iPhone app(LandscapeRight Mode), I have added a Image view named
I am working on iPhone app. I have added Navigation bar Background image With
I am working on a iPhone app and trying to add a German localization.
Currently i am working in iPhone app, Using UIImageView to set a background image
I am working on an iPhone app with Apple Push Notification integration. I have
I'm working on an iphone app and want to have a page showing multiple
I am working on an iPhone app, in which I have to enlist all
I am working on an iphone app in IOS5 that user storyboards. I have
Greetings! I have a working iPhone app (huzzah!) that uses a MainView.xib containing a
I have been working with iPhone app as developer and now my PM(Project Manager)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.