How to reset to identity the “current transformation matrix” with some CGContext function?

浪子不回头ぞ 提交于 2019-12-04 06:21:50

Get current transformation matrix via CGContextGetCTM, invert it with CGAffineTransformInvert and multiply the current matrix by the inverted one (that's important!) with CGContextConcatCTM. CTM is now identity.

Note that inverting the current CTM with CGAffineTransformInvert does not work if your current CTM is singular.

The obvious case is if previously CGContextConcatCTM was performed with matrix CGAffineTransformMake(0, 0, 0, 0, 0, 0).

The save/restore operations are probably a single memory copy of a memory region comparable to the size of the identity matrix (twice or thrice the size). It might only happen for the save operation. Consider that this is probably not much slower than a nop FUNCTION call. Each graphic operation is in the scale of several multiplication operation and I'm guessing this happens more than once in your code for each save/restore cycle. The time of one graphic operation is probably larger than a single save/restore cycle.

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