在Quartz中旋转图像?图像颠倒了! (iPhone)

问题描述:

  • 我不想变换整个上下文。

我正在制作一款Quartz游戏,我正在用线条,缩影和椭圆绘制我的玩家。在Quartz中旋转图像?图像颠倒了! (iPhone)

然后我有diamong.png,我在0,0在屏幕左上角渲染。

问题是...

它呈现颠倒!

我该如何将它旋转180度?

下面是我的一些代码:

CGImageRef diamondImage = CGImageRetain([UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"Diamond.png" ofType:nil]].CGImage); 
CGContextDrawImage(context, CGRectMake(0, 0, 32, 24), diamondImage); 

如果它的任何帮助,我使用风景模式,与家庭按钮向右。它的定义都在我的.plist,在我的ViewController的

-shouldAutorotateToInterfaceOrientation:interfaceOrientation:

我将如何旋转/转换呢?

为什么不使用

[[UIImage imageWithContentsOfFile:…] drawInRect:CGRectMake(0, 0, 32, 24)]; 

?这需要关心你的坐标变换。


如果必须使用CGContextDrawImage,则转换整个上下文是唯一的方法。您可以使用以下方式恢复到原始状态:

CGContextSaveGState(context); 
// transform ... 
// draw ... 
CGContextRestoreGState(context);