【问题标题】:Objective - C, fastest way to show sequence of images in UIImageView [duplicate]Objective - C,在 UIImageView 中显示图像序列的最快方法 [重复]
【发布时间】:2012-06-21 02:48:45
【问题描述】:

可能重复:
How to efficiently show many Images? (iPhone programming)

我有数百张图像,它们是一个动画的帧图像(每秒 24 张图像)。每个图像尺寸为 1024x690

我的问题是,我需要在 UIImageView 中制作平滑动画迭代每个图像帧。
我知道我可以使用 UIImageView 的动画图像。但由于内存问题,它崩溃了。

另外,我可以使用imageView.image = [UIImage imageNamed:@""] 来缓存每个图像,这样下一个重复动画就会流畅。但是,缓存大量图片会导致应用崩溃。

现在我使用imageView.image = [UIImage imageWithContentsOfFile:@""],它不会使应用程序崩溃,但不会使动画如此流畅。

也许有更好的方法来制作好的帧图像动画?

也许我需要做一些准备,以便以某种方式获得更好的结果。我需要你的建议。谢谢!

【问题讨论】:

  • UIImageView *animation.frame = [UIImageView new];动画.animationImages = 动画帧; // 图片数组 animation.animationDuration = 1.25;动画.animationRepeatCount = 1;动画.hidden = YES;试试这个

标签: objective-c ios performance ios4 uiimageview


【解决方案1】:

您可以尝试在内存中一次缓存 10 个图像(您可能必须使用正确的限制——我怀疑它是 10 个)。每次更改 imageView 的图像时,您都可以执行以下操作:

// remove the image that is currently displayed from the cache
[images removeObjectAtIndex:0];
// set the image to the next image in the cache
imageView.image = [images objectAtIndex:0];
// add a new image to the end of the FIFO
[images addObject:[UIImage imageNamed:@"10thImage.png"]];

【讨论】:

    【解决方案2】:

    您可以在这里找到答案:How to efficiently show many Images? (iPhone programming)

    总结该链接中所说的内容,如果您使用与 UIKit 相反的 Core Animation 和 OpenGL 等低级 API,则在显示许多图像时可以获得更好的性能。

    【讨论】:

      【解决方案3】:

      您可以使用数组创建包含多个图像的缓冲区。可以使用 imageWithContentsOfFile 从后台线程(例如并发 GCD 异步)加载/填充此图像缓冲区数组。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-10-29
        • 1970-01-01
        • 2017-12-18
        • 2015-07-25
        • 1970-01-01
        相关资源
        最近更新 更多