1

This is my drawInContext method:

UIImage *img = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"myImage" ofType:@"png"]];
CGRect cropRect = CGRectMake(0, 0, 175, 175);
CGImageRef imageRef = CGImageCreateWithImageInRect([img CGImage], cropRect);

CGRect imageRect;

imageRect.origin = CGPointMake(0, 0);
imageRect.size = CGSizeMake(175, 175);

CGContextDrawImage(UIGraphicsGetCurrentContext(), imageRect, imageRef);
CGImageRelease(imageRef);

My image is upside down, how can I change it? What's wrong with my code? How can I change the image become normal?? thx .

Tattat
  • 15,548
  • 33
  • 87
  • 138
  • possible duplicate of http://stackoverflow.com/questions/506622/cgcontextdrawimage-draws-image-upside-down-when-passed-uiimage-cgimage – David Gelhar May 04 '10 at 13:14

1 Answers1

2

Instead of this:

CGContextDrawImage(UIGraphicsGetCurrentContext(), imageRect, imageRef);

do this:

[img drawInRect:CGRectMake(0, 0, 175, 175)]

CGContextDrawImage doesn't preserve orientation.

Rob
  • 792
  • 2
  • 7
  • 15