[英]How can I achieve fast frame rate of a JPG image display on iOS?
我已经在iPhone 3GS上获得了近10 FPS的可靠JPG切换,但是我发现使用GPU和CALayer可以更快。 您能帮我确定如何实现吗? 我在下面尝试了一些不同的东西。
这就是我一直在使用的…
#define FPS 12.0
[NSTimer scheduledTimerWithTimeInterval:(1.0 / FPS) target:self selector:@selector(animateMethod:) userInfo:nil repeats:YES];
请注意,方法baseImagePath为每次调用返回不同的路径。
- (void)animateMethod:(NSTimer *)timer
{
self.imageView.image = [UIImage imageWithContentsOfFile:[self baseImagePath]];
}
这是我尝试过的...
- (void)animateMethod:(NSTimer *)timer
{
self.layerView.layer.contents = [(__bridge id)([[UIImage imageWithContentsOfFile:[self baseImagePath]] CGImage]);
}
我认为您可以从不同的角度来解决这个问题,以获得所需的结果。 您可以利用UIImageView
的动画属性来完成此任务。 您可以按照希望它们在动画中显示的顺序先将图像预加载到数组中。 然后设置您的UIImageView
。
NSMutableArray *images = [NSMutableArray array];
for (int i = 0; i < 16; i++) {
UIImage *image = [UIImage imageNamed: [NSString stringWithFormat: @"image_%d.jpg", i]];
[images addObject: image];
}
[self.myImageView setAnimationImages: images];
[self.myImageView setAnimationDuration: 0.5]; // Image view will loop through all images in half a second.
[self.myImageView setAnimationRepeatCount: 0]; // Infinite looping
[self.myImageView startAnimating];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.