在Quartz中旋转图像?图像是颠倒的! (苹果手机) [英] Rotate image in Quartz? Image is upside down! (iPhone)

查看:102
本文介绍了在Quartz中旋转图像?图像是颠倒的! (苹果手机)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


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

我正在制作游戏使用Quartz,我用线条,小数和椭圆来绘制我的播放器。

I'm making a game with Quartz, and I'm drawing my player with lines, rects and ellipses.

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

And then I have diamong.png which I rendered at 0,0 in the top left of the screen.

问题是......

它呈现颠倒!

如何将它旋转180度?

How would I rotate it 180 degrees?

这是我的一些代码:

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

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

If it's of any help, I'm using Landscape mode, with home button to the right. It's defined both in my .plist, and in my ViewController's


-shouldAutorotateToInterfaceOrientation:interfaceOrientation:

-shouldAutorotateToInterfaceOrientation:interfaceOrientation:

我如何旋转/转换它?

推荐答案

为什么不使用

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

?这会照顾你的坐标变换。

? This take cares of the coordinate transforms for you.

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

If CGContextDrawImage must be used, transforming the entire context is the only way. You can restore to the original state using:

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

这篇关于在Quartz中旋转图像?图像是颠倒的! (苹果手机)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆