在Quartz中旋转图像?图像是颠倒的!(苹果手机)

Joh*_*sen 0 iphone image objective-c rotation quartz-graphics

  • 我不想改变整个上下文.

我正在用Quartz制作一个游戏,我正在用线条,椭圆和椭圆来绘制我的播放器.

然后我有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);
Run Code Online (Sandbox Code Playgroud)

如果它有任何帮助,我正在使用横​​向模式,右侧有主页按钮.它在我的.plist和我的ViewController中定义

-shouldAutorotateToInterfaceOrientation:interfaceOrientation:

我该如何旋转/转换它?

ken*_*ytm 5

为什么不用

[[UIImage imageWithContentsOfFile:…] drawInRect:CGRectMake(0, 0, 32, 24)];
Run Code Online (Sandbox Code Playgroud)

?这会照顾您的坐标变换.


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

CGContextSaveGState(context);
// transform ...
// draw ...
CGContextRestoreGState(context);
Run Code Online (Sandbox Code Playgroud)