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 6820593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:26:35+00:00 2026-05-26T21:26:35+00:00

In my iPhone app, I am using the iPhone’s camera to take a photo

  • 0

In my iPhone app, I am using the iPhone’s camera to take a photo and save it do disk (the application’s documents folder). This is how i save it:

[UIImageJPEGRepresentation(photoTaken, 0.0) writeToFile:jpegPath atomically:YES];

Using the most compression, I figured reading the image from disk would be quick. But its not! I use the image as the background image for a button in one of my views. I load it like this:

[self.frontButton setBackgroundImage:[UIImage imageWithContentsOfFile:frontPath] forState:UIControlStateNormal];

When I navigate to the view with this button, it is slow and choppy. How do I fix this?

  • 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-26T21:26:36+00:00Added an answer on May 26, 2026 at 9:26 pm

    +imageWithContentsOfFile: is synchronous, so the UI on your main thread is being blocked by the image loading from disk operation and causing the choppiness. The solution is to use a method that loads the file asynchronously from disk. You could also do this in a background thread. This can be done easily by wrapping the +imageWithContentsOfFile: in dispatch_async(), then a nested dispatch_async() on the main queue that wraps -setBackgroundImage: since UIKit methods need to be run on the main thread. If you want the image to appear immediately after the view loads, you’ll need to pre-cache the image from disk so it’s in-memory immediately when the view appears.

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
    
        UIImage *image = [UIImage imageWithContentsOfFile:frontPath];
    
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.frontButton setBackgroundImage:image forState:UIControlStateNormal];
        });
    
    });
    

    As an aside, if the button image happens a gradient, consider using the following properties to ensure the image file loaded from disk is tiny:

    - (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets
    

    or (deprecated, only use if you need to support iOS 4.x):

    - (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Am looking into developing an iPhone native app using Titanium Developer Since this is
I am developing an iPhone app using cocos2d and box2d.In this app i require
This is about an iPhone App using MKMapKit: I created a custom MKAnnotationView for
This is about an iPhone App using MKMapKit: I created a custom MKAnnotationView for
I am using this query to fetch data from webserver onto my iPhone app
I am sending an email from my iPhone app using MFMailComposeViewController. This works fine
I am trying to develop an iPhone app using PhoneGap and jQuery Mobile. This
I have an iPhone app using a UINavigationController. On the fourth controller of the
I'm creating an iphone app using xcode 4.2, and trying to use the AVFoundation
I've been creating an iPhone App using Core Data. First of all, does it

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.