Tutorial :Rotate image in Quartz? Image is upside down! (iPhone)



Question:

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


Solution:1

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);  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »