`
jsntghf
  • 浏览: 2527604 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

图片旋转

    博客分类:
  • iOS
阅读更多

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
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics