0
  • 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

-shouldAutorotateToInterfaceOrientation:interfaceOrientation:

How would I rotate/transform it?

STW
  • 44,917
  • 17
  • 105
  • 161
Johannes Jensen
  • 1,228
  • 2
  • 18
  • 28

1 Answers1

5

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);
kennytm
  • 510,854
  • 105
  • 1,084
  • 1,005