 |
 |
|
 |
07-02-2009, 11:37 AM
|
#1 (permalink)
|
|
New Member
Join Date: Jun 2009
Posts: 3
|
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];
}
|
|
|
07-02-2009, 04:51 PM
|
#2 (permalink)
|
|
Senior Member
iPhone Dev SDK Supporter
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 2,567
|
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.
__________________
|
|
|
 |
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
» Advertisements |
» Online Users: 463 |
| 54 members and 409 guests |
| Adam3001, adison, AdvertiseSpace, Alexman, amulter, Axeva, bbc z, bgeerdes, Chilibird, Cooper_1988, CunningCat, damienbern, develsolutions, DonneonoInvoft, Eagle11, Eskema, Furniture_lover, fxshot, gbh, Gi-lo, Glibnobin, harrytheshark, hazmat82, headkaze, Hendrika, iGeorG, ImpresionesWeb, iphonedave, itsugawakun, jbro, joeprogrammer, jojo453, krishy, LightRoom, Locker, lukeca, LunarMoon, malaki1974, mauri, mcgrath3, ng93, phuongth, racer_X, rhawkey, Rudy, schoash, seymores, sinclairgf, smasher, tappix, tateyaku, upperhouse, vitalic, xiko |
| Most users ever online was 779, 05-11-2009 at 09:55 AM. |
» Stats |
Members: 24,198
Threads: 38,971
Posts: 170,967
Top Poster: smasher (2,567)
|
| Welcome to our newest member, Hendrika |
|