我在序列中使用150张图片进行动画制作。
这是我的代码。
NSMutableArray * arrImages = [[NSMutableArray alloc] initWithCapacity:0];
for(int i = 0; i <=158; i++)
{
UIImage* image = [UIImage imageNamed:[NSString stringWithFormat:@"baby%05d.jpg",i]];
[arrImages addObject:image];
}
babyimage.animationImages = arrImages;
[arrImages release];
babyimage.animationDuration = 6.15; [babyimage startAnimating];
但它占用了太多内存。播放1分钟后,它会在控制台中显示内存警告。然后crashed.i也降低了图像分辨率,我不能使它低于150以获得更好的质量。
有没有更好的方法来做这个没有内存问题的动画。 非常感谢 请帮忙......
答案 0 :(得分:3)
尝试,
而不是[UIImage imageNamed:[NSString stringWithFormat:@"baby%05d.jpg",i]]
使用
[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"baby%05d.jpg",i] ofType:nil]]
原因是imageNames缓存了图像,在释放内存警告之前不会释放
希望它可以帮助你..
编辑: -
此外,不要将整个图像存储到数组中,只需保存图像名称(如果您需要或不保存任何内容)。这也需要很多记忆
答案 1 :(得分:0)
我不知道你没有指定动画是什么。但如果我在做代码,我会遵循以下算法。
假设在特定时间只显示一张图像,但在转换过程中,您最终会在某种程度上进行两次卷积。
procedureAnimate:
photo_1 = allocate(file_address_array[i++])
while i < MAX_PHOTOS
photo_2 = allocate(file_address_array[i++])
photo_3 = allocate(file_address_array[i++])
perform_animation(photo_1, photo_2)
release(photo_1)
photo_1 = photo_2
photo_2 = photo_3
release(last_two)
我不确定这是否是做这种事的_perfect_way。但这会更有效率。
(可能是分配/发布登录有些严重错误,但这与我早上5.14 AM的工作一致)。如果这不起作用,请告诉我。