图片旋转

UIImage+Rotate.h

 

#import <UIKit/UIKit.h>

@interface UIImage (Rotate)

- (UIImage*)rotateImageByAngle:(NSString *)angle;

@end

 

UIImage+Rotate.m

 

#import "UIImage+Rotate.h"

@implementation UIImage (Rotate)

- (UIImage*)rotateImageByAngle:(NSString *)angle{
    CGSize rotatedSize = self.size;
    UIGraphicsBeginImageContext(rotatedSize);    
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextTranslateCTM(ctx, rotatedSize.width / 2, rotatedSize.height / 2);    
    CGContextRotateCTM(ctx, M_PI * [angle intValue] / 180);
    CGContextScaleCTM(ctx, 1.0, -1.0);
    CGContextDrawImage(ctx, CGRectMake(-self.size.width / 2, -self.size.height / 2, self.size.width, self.size.height), [self CGImage]);    
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newImage;
}

@end

你可能感兴趣的:(ios,iPhone,图片旋转)