Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Improve transparent image drawing performance

My Goal I'd like to improve the drawing performance of transparent images in an animation by using the fact that the background beyond the images is not changing during the animation.

The Context I need to build an animation of 100 images (~5sec). I can't use the startAnimating function of UIImageView since 100 images is too big to be put in memory. So I've decided to use a timer and to change directly the image in the UIImageView. The problem is that for transparent images, the drawing is too slow (5 FPS for full screen images with transparency; 22 FPS for images without transparency).

When the animation is launched, I know that the pixel beyond my images will not changed until the animation is finished.

Question Is there a way to improve the drawing performance of my transparent images by using the fact that the background beyond the image don't change during the animation ?

Note that the background beyond the image can change before I launch the animation so I can't put the background directly in my images.

like image 823
CedricSoubrie Avatar asked Mar 11 '26 13:03

CedricSoubrie


1 Answers

Unfortunately your options will be somewhat limited. Because you do not know the background ahead of time-that is, before the animation runs-then the transparent images will need to be composited atop the background when the animation runs. I see no way to work around that.

You should be able to use the -animationImages feature of UIImageView, as it should not load and keep all the images in memory but rather load them when they are needed to be displayed. Have you tried this method, and if so what were the results?

The only other option I can think of would be to drop down to using OpenGL textures, possible using PVRTC compressed textures that use less memory so that you can keep more of them loaded and avoid any slowdown due to image decompression while your animation is running.

like image 149
Jason Foreman Avatar answered Mar 14 '26 10:03

Jason Foreman