简体   繁体   中英

Image animation with Core Graphics is too slow

I am creating an animation using Core Graphics and CADisplayLink.

I redraw an image to the current graphics context with every CADisplayLink loop call. Here is the function where I draw the image with every call:

 - (void) drawImage {

//img is some uiimage
CGRect r = CGRectMake(0, 0, img.size.width, img.size.height);
CGImageRef i = [img CGImage];
CGContextDrawImage(context, r, i);



 }

The problem is that the animation runs to slow and I believe this is because I am creating the image bitmap from scratch each time instead of somehow caching it. Is there a way to cache bitmaps? if so how?

Thanks in advance.

Without seeing more of your code, or some profiler output, it's impossible to say for sure why your code is slow. However, instead of drawing the image at all, you should try using a UIImageView . Just change the image view's frame each time CADisplayLink notifies you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM