Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone
($4.99)

Shape Up
($0.99)

Your First iPhone App
($1.99)

iVidCam Free
(free)

Kid Art
($0.99)

iPUBQUIZ
(£1.19)

ArtStudio
($3.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development > iPhone SDK Development - Advanced Discussion

Reply
 
LinkBack Thread Tools Display Modes
Old 07-02-2009, 11:37 AM   #1 (permalink)
New Member
 
Join Date: Jun 2009
Posts: 3
Default Image animation runs slow first time, then fast

Hi, I have an array of images (about 100 320x240px 8k jpgs) that I run through using a timer. The first time the timer cycles through the images it goes very slowly--i'm guessing about 10fps. After that, it will play quickly (maybe up to 100fps).

First, what's going on here? I'm super curious. (some kind of memory or cpu throttling?) Second, I want the animation to run fast the first time. The only fix I've found is to run the animation once with the UIImageView offscreen. This takes a few seconds, however, which adds to the loading time. Is there a better way of "preloading" these images?

Here's my code. I'm on a 3g iphone with 3.0 sdk.

Code:
-(IBAction)startPressed:(id)sender{
	
	NSTimer *timer;
	
	timer = [NSTimer scheduledTimerWithTimeInterval: 0.01
							target: self
							selector:@selector(handleTimer:)
							userInfo: nil
							repeats: YES];
	
}

- (void) handleTimer: (NSTimer *) timer
{	
	static int i = 0;

	if(i > imageArray.count - 1){
		[timer invalidate];
		i=0;
		return;
	}

	finger.image = [imageArray objectAtIndex:i];
        NSLog(@"%d", i);
	i++;
}

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {	
	int i;
	NSString *loadString;
	imageArray = [[NSMutableArray alloc] init];
	
	for(i = 1; i < 100; i++) {
		loadString = [NSString stringWithFormat:@"finger %03d", i]; 	
		[imageArray addObject:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:loadString ofType:@"jpg"]]];
		NSLog(loadString);
	}
	
	finger.image = [imageArray objectAtIndex:0];
	NSLog(@"Array Count: %d", [imageArray count]);
    [super viewDidLoad];

}
rusew is offline   Reply With Quote
Old 07-02-2009, 04:51 PM   #2 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 2,567
Default

Check the docs for UIImageView - there's an animationImages property that should run the whole animation for you, without needing a timer.

However, you may still run into memory problems on the device. Uncompressed, we're talking about 100 * 320 * 240 * 4 bytes = about 29 MB of memory for your images. That's too much for your program to use.

You'll probably have to create a movie file to get what you want.
__________________
smasher is online now   Reply With Quote
Reply

Bookmarks

Tags
animation, nsmutablearray, 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


Enter the iPhone App Challenge!  Win $500!
» Advertisements
» Stats
Members: 24,198
Threads: 38,971
Posts: 170,967
Top Poster: smasher (2,567)
Welcome to our newest member, Hendrika
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 12:43 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0