#import <QuartzCore/QuartzCore.h>
+ (UIImage*)transformImageSymmetrically:(UIImage*)originalImage
{
UIImage *transformedImage = originalImage;
if (!isUsingBackCamera) {
//建立一個暫存用的UIImageView
UIImageView *tempImageView = [[UIImageView alloc] initWithImage:originalImage];
UIGraphicsBeginImageContext(tempImageView.frame.size);
//這三行跟下面mark起來的七行,效果是一樣的,可以互相取代
CGContextRef context = UIGraphicsGetCurrentContext();
CGAffineTransform flipHorizontal = CGAffineTransformMake( -1.0, 0.0, 0.0, 1.0, tempImageView.frame.size.width, 0.0 );
CGContextConcatCTM(context, flipHorizontal);
// CGImageRef imgRef = originalImage.CGImage;
// CGFloat width = CGImageGetWidth(imgRef);
// CGFloat height = CGImageGetHeight(imgRef);
// CGAffineTransform transform = CGAffineTransformIdentity;
// transform = CGAffineTransformMakeTranslation(width,0.0);
// transform = CGAffineTransformScale(transform, -1.0, 1.0);
// CGContextConcatCTM(context, transform);
[tempImageView.layer renderInContext:context];
transformedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[tempImageView release];
}
return transformedImage;
}
沒有留言:
張貼留言