开发者

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.

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

Problem is...

It renders upside down!

How would I rotate it 180 degrees?

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

开发者_Go百科

-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. You can restore to the original state using:

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜