Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 03-30-2011, 02:58 PM   #1 (permalink)
Registered Member
 
Join Date: Dec 2010
Location: Cleveland, Ohio
Posts: 26
Panther is on a distinguished road
Default [UIImageView setImage] slow?

I have a UITableView-like setup in my app. It's a scrolling view of magazine cover thumbnails, and the thumbnail images only get loaded when they are about to become visible. The scrolling was really lagging on the device, as I was loading three images from disk for every "cell." So, I'm using GCD to load an image in the background, then set it to a UIImageView in the main thread, but setting the image to the image view in the main thread still causes jerkiness when scrolling. Here's the relevant code...

Code:
    NSString *magDirectoriesDirectory = [FileUtilities magDirectoriesDirectory];
    NSString *magDirectory = [magDirectoriesDirectory stringByAppendingPathComponent:magTitle];
    NSString *coverImagePath = [magDirectory stringByAppendingPathComponent:COVER_IMAGE_NAME];
    
    dispatch_async(queue, ^{
        UIImage *image = [UIImage imageWithContentsOfFile:coverImagePath];
        dispatch_async(dispatch_get_main_queue(), ^{
            magCoverImageView.image = image;
        });
    });
I'm know that it's setting the thumbnail to the image view that causes the problem because when I comment that line of code, it runs smoothly.

I also load a shadow image at the same time I load the thumbnail image.

Code:
    UIImage *shadow = [UIImage imageNamed:@"Rack_MagShadow.png"];
    shadowImageView.image = shadow;
Strangely, this causes no lag at all.

So, why is setting the thumbnail image to the image view causing a big lag, while setting the shadow image doesn't? They're the same size, by the way.
Panther is offline   Reply With Quote
Old 08-19-2011, 08:59 AM   #2 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 4
rusew is on a distinguished road
Default

Try using the global queue instead of main. That is:

Code:
dispatch_async(dispatch_get_global_queue(0, 0), ^{
    //load images
});
rusew is offline   Reply With Quote
Old 08-19-2011, 12:19 PM   #3 (permalink)
Super Moderator
 
Join Date: Oct 2009
Location: San Diego, CA
Posts: 1,586
JasonR is on a distinguished road
Default

imageNamed: caches the file in memory, while imageWithContentsOfFile: loads it from the file each time.
__________________
My development blog: http://jrinn.com
JasonR is offline   Reply With Quote
Reply

Bookmarks

Tags
gcd, setimage, uiimage, uiimageview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 368
12 members and 356 guests
condor304, dansparrow, dre, ilmman, LezB44, michelle, Objective Zero, samdanielblr, Sami Gh, shagor012, thephotographer, tinamm64
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,119
Posts: 402,896
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:36 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0