views:

56

answers:

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 .

+1  A: 

Instead of this:

CGContextDrawImage(UIGraphicsGetCurrentContext(), imageRect, imageRef);

do this:

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

CGContextDrawImage doesn't preserve orientation.

Rob