Hi, I'm trying to correct the camera's image orientation.
I'm using this function lifted out of a book but it's returning an image.
Can you see what's wrong?
I'm using ios 5.
- (UIImage *)fixOrientation: (UIImage *) image
{
CGSize size = image.size;
if (image.imageOrientation == UIImageOrientationLeft || image.imageOrientation == UIImageOrientationRight) {
size = CGSizeMake(image.size.height, image.size.width);
}
UIGraphicsBeginImageContext(size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGAffineTransform transform = CGAffineTransformIdentity;
switch (image.imageOrientation) {
case UIImageOrientationUp:
NSLog(@"fix up");
transform = CGAffineTransformRotate(transform, M_PI);
CGContextConcatCTM(context, transform);
break;
case UIImageOrientationDown:
break;
default:
break;
}
//draw
//[image drawAtPoint:CGPointMake(0.0f, 0.0f)];
[image drawInRect:CGRectMake(0.0, 0.0, image.size.width, image.size.height)];
UIImage *newimg = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newimg;
}