简体   繁体   English

旋转石英图像? 图像颠倒了! (苹果手机)

[英]Rotate image in Quartz? Image is upside down! (iPhone)

  • I don't want to transform the ENTIRE context. 我不想改变整个上下文。

I'm making a game with Quartz, and I'm drawing my player with lines, rects and ellipses. 我正在用Quartz制作游戏,并且在游戏中用线条,矩形和椭圆形画玩家。

And then I have diamong.png which I rendered at 0,0 in the top left of the screen. 然后,我在屏幕左上角的0,0渲染了diamong.png。

Problem is... 问题是...

It renders upside down! 它呈现颠倒!

How would I rotate it 180 degrees? 我将如何旋转180度?

Here's some of my code: 这是我的一些代码:

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

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 它在我的.plist和ViewController的

-shouldAutorotateToInterfaceOrientation:interfaceOrientation: -shouldAutorotateToInterfaceOrientation:interfaceOrientation:

How would I rotate/transform it? 我将如何旋转/变形?

Why not use 为什么不使用

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

? This take cares of the coordinate transforms for you. 这将为您处理坐标变换。


If CGContextDrawImage must be used, transforming the entire context is the only way. 如果必须使用CGContextDrawImage ,则转换整个上下文是唯一的方法。 You can restore to the original state using: 您可以使用以下方法恢复到原始状态:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM