更快的 iPhone PNG 动画

发布于 2024-10-01 01:45:31 字数 425 浏览 3 评论 0原文

目前,我的计时器上有一个 PNG 动画,每 0.01 秒触发一次。然而,性能并不是最佳的,而且动画速度明显很慢。我有超过 2000 张图片。有更好的方法来实现这一点吗?我在下面发布了与我的方法类似的内容。

timer_ = [NSTimer scheduledTimerWithTimeInterval:.01 target:self
selector:@selector(switchImage) userInfo:nil repeats:YES];


-(void)switchImage 
{
   p = [p stringByAppendingFormat:@"/Movie Clipping 1 000%i.png",i];
   imageView_.image = [UIImage imageWithContentsOfFile:p];
   i = i++;
}

Currently I have a PNG animation on a timer that is firing every .01 seconds. However, performance isn't optimal and the animation is visibly slow. I have over 2000 images. Is there a better way to accomplish this? I've posted something similar to my approach below.

timer_ = [NSTimer scheduledTimerWithTimeInterval:.01 target:self
selector:@selector(switchImage) userInfo:nil repeats:YES];


-(void)switchImage 
{
   p = [p stringByAppendingFormat:@"/Movie Clipping 1 000%i.png",i];
   imageView_.image = [UIImage imageWithContentsOfFile:p];
   i = i++;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

风向决定发型 2024-10-08 01:45:31

您的 PNG 的具体大小(我的意思是 KB 以及确切的像素大小)?

我们在这方面做了很多工作,并且在 pad 上播放大约 500x500 的动画没有任何问题。所以我只是想知道,谢谢。

一个紧迫的问题是您试图以 100hz、每秒 100 次的速度运行?!

这绝对是不可能的。没有什么能以 100 fps 运行。 20fps 是“极其流畅”,30fps 是“极其流畅”,40fps 是“如果能够实现,则令人难以置信的人类视觉研究级流畅”,而 100 fps 则无法实现。

这与 OpenGLES 完全没有任何关系。

普通环境将为您快速加载帧。

所以首先回到 30 fps(最多!)并丢弃每第二张和第三张图像,以便动画看起来相同。即,“i=i++”在您的代码行中变为“i+=3”。

这很可能是一个压倒性的问题,正在毁掉你的努力!

下一个问题!如果您确实像这样加载每个图像,那么您几乎肯定需要在使用一对类似的行时动态释放它们。 ..

[happy.image release];
happy.image = [[UIImage alloc] initWithContentsOfFile:
    [[NSBundle mainBundle] pathForResource:@"blah" ofType:@"png"]];

如果你不这样做,它就不会起作用。

下一个问题!使用视频的想法不好,但是你可以使用日常的动画图像吗?因此...

#define BI(X) [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@X ofType:@"tif"]]

    happyDays  = [[NSArray alloc] initWithObjects:
            BI("hh00"), BI("hh01"), BI("hh02"), BI("hh03"), BI("hh04"), BI("hh05"), BI("hh06"), BI("hh07"), BI("hh08"), BI("hh09"), 
            BI("hh10"), BI("hh11"), BI("hh12"), BI("hh13"), BI("hh14"), BI("hh15"), BI("hh16"), BI("hh17"), BI("hh18"), BI("hh19"), etc etc etc
            nil];

    animArea.animationImages = happyDays;
    animArea.animationDuration = 2.88;
    // that is overall seconds. hence: frames divided by about 30 or 20.
    [animArea startAnimating];

对你的情况没有好处?

无论如何,总而言之,你的问题是 100 fps。更改为 20 fps 就没有问题了。并让我们知道精确的图像大小(kb / xy)。

exactly what size (I mean KB and also the exact pixel size) are your PNGs?

We have done a lot of work on this and have no trouble playing animations, on the pad, of about say 500x500. So I'm just wondering, thanks.

One immediate problem is that you are trying to run at 100hz, 100 times per second??!

That is absolutely impossible. Nothing runs at 100 fps. 20fps is "extremely smooth", 30fps is "staggeringly smooth", 40fps is "mindboggling human-vision-research-level smooth if it could be achieved" and 100 fps cannot be achieved.

This has absolutely utterly nothing whatsoever to do with OpenGLES.

The ordinary environment will load frames very quickly for you.

So first go back to 30 fps (at most!) and throw away every 2nd and 3rd image so the animation looks the same. ie, "i=i++" becomes "i+=3" in your line of code.

it is likely that this is the overwhelming problem that is ruining your efforts!

Next problem! If you do load up each image like that as you go, you will almost certainly need to release them all on the fly as you go with a pair of lines something like...

[happy.image release];
happy.image = [[UIImage alloc] initWithContentsOfFile:
    [[NSBundle mainBundle] pathForResource:@"blah" ofType:@"png"]];

If you don't do that it just won't work.

Next problem! The idea of using video is no good, but could you just use an everyday animated image? Thus...

#define BI(X) [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@X ofType:@"tif"]]

    happyDays  = [[NSArray alloc] initWithObjects:
            BI("hh00"), BI("hh01"), BI("hh02"), BI("hh03"), BI("hh04"), BI("hh05"), BI("hh06"), BI("hh07"), BI("hh08"), BI("hh09"), 
            BI("hh10"), BI("hh11"), BI("hh12"), BI("hh13"), BI("hh14"), BI("hh15"), BI("hh16"), BI("hh17"), BI("hh18"), BI("hh19"), etc etc etc
            nil];

    animArea.animationImages = happyDays;
    animArea.animationDuration = 2.88;
    // that is overall seconds. hence: frames divided by about 30 or 20.
    [animArea startAnimating];

No good for your situation?

Anyway, in one word your problem is 100 fps. Change to 20 fps and you will have no trouble. And let us know the precise image size (kb / x.y).

独孤求败 2024-10-08 01:45:31

CADisplayLink 用于管理 fps?

OpenGLES需要花时间将图像转换为纹理,而纹理需要仔细的内存管理。当内存不够的时候,会生成全白的纹理。

How about CADisplayLink for managing fps?

OpenGLES needs to spend time to convert an image to texture, and texture needs careful memory management. When memory is not enough, it will generate a whole white texture.

霊感 2024-10-08 01:45:31

将动画编码为视频并播放该视频。

Encode your animation as a video and play the video instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文