开发者

iOS4: how do you set a CGContext's transormation matrix to an absolute number?

I'm currently making a graphical application, and it will make my life a lot easier if I simply flip the context's transform matrix upside down whenever I want to draw something upside down, which is quite frequently. However, the only command I can find that supports this is CGContextScaleCTM. This is fine I guess, but it's an additive (well, multiplicative) process. If I scale it to 50% size, I then have to know that I've done that and enlarge it to 200% size after, which means retrieving the current matrix and doing a spot of mathematics every time I want to reset it to its original state of {1,0,0,1,0,0} which is also pretty darn often. There seem to be ways of doing this programmatically, but it seems extremely wasteful to spend processor time getting, fetching and multiplying matrices when all I really need to do is set the current 开发者_Python百科transformation matrix to its absolute value.

However, I'm having great trouble discovering HOW, and it's really, really silly. I assume that the transformation matrix is stored somewhere in the CGContextRef structure as a CGAffineTransform, but I can't find a good document anywhere to tell me what its name is so that I can set it manually, and I don't even know if this would work. Can anyone help on this front?

-Ash


I believe the only way to do what you are saying is what you are thinking of doing, that is using CGContextScaleCTM, however i don't see how the mathematics to check if you have it doubled/halved etc would be used that frequently if you only call them when you absolutely need to.

Update while typing: Have you tried using CGContextSaveGState and CGContextRestoreGState? I'm not exactly sure if its what you are looking for, but it would allow you to go back and forth between your halved/doubled i would think fairly easily?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜