Static background for CGContext

青春壹個敷衍的年華 提交于 2019-12-05 17:30:40

A call to CGContextDrawImage with a CGImageRef with the the same size dimensions as the CGRect is fast. Setup a CGImageRef with the background image in code that gets run less often than every frame, such as the view's initialization code. If this background image is changing, build the image in the program logic code, not the draw refresh code.

The worst you can do is access the image from a file each time. Some time can be saved by not accessing the CGImageRef from within a heavier object. A call like [someUIImageObject CGImage] will add the overhead of a message send, whereas an access to a CGImageRef type ivar in the same object containing the drawing code will not.

If your source image is not the right size, first draw it into a CGImageRef at the needed size once, and reuse it in your drawing code.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!