Reputation: 15778
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 .
Upvotes: 1
Views: 1208
Reputation: 780
Instead of this:
CGContextDrawImage(UIGraphicsGetCurrentContext(), imageRect, imageRef);
do this:
[img drawInRect:CGRectMake(0, 0, 175, 175)]
CGContextDrawImage doesn't preserve orientation.
Upvotes: 2