在iPhone上旋转jpg

问题描述:

我有一个应用程序,通过相机拍摄照片或从库中选择它并将其保存为jpg文档文件夹。但在保存之前,我想旋转90度。在iPhone上旋转jpg

希望任何人都可以帮助我。

感谢

对于iOS 4及更高版本:
UIImage imageWithCGImage:scale:orientation:

对于iOS 3和以前:
How to Rotate a UIImage 90 degrees?

static inline double radians (double degrees) {return degrees * M_PI/180;} 
UIImage* rotate(UIImage* src, UIImageOrientation orientation) 
{ 
    UIGraphicsBeginImageContext(src.size); 

    CGContextRef context = UIGraphicsGetCurrentContext(); 

    if (orientation == UIImageOrientationRight) { 
     CGContextRotateCTM (context, radians(90)); 
    } else if (orientation == UIImageOrientationLeft) { 
     CGContextRotateCTM (context, radians(-90)); 
    } else if (orientation == UIImageOrientationDown) { 
     // NOTHING 
    } else if (orientation == UIImageOrientationUp) { 
     CGContextRotateCTM (context, radians(90)); 
    } 

    [src drawAtPoint:CGPointMake(0, 0)]; 

    return UIGraphicsGetImageFromCurrentImageContext(); 
} 
+0

适用于iOS 4.0及更高版本。需要编辑3.x – eemceebee

+0

以匹配这两个sdk的 –

你可以不喜欢它

static inline double radians (double degrees) {return degrees * M_PI/180;} 
UIImage* rotate(UIImage* src, UIImageOrientation orientation) 
{ 
    UIGraphicsBeginImageContext(src.size); 

    CGContextRef context = UIGraphicsGetCurrentContext(); 

    if (orientation == UIImageOrientationRight) { 
     CGContextRotateCTM (context, radians(90)); 
    } else if (orientation == UIImageOrientationLeft) { 
     CGContextRotateCTM (context, radians(-90)); 
    } else if (orientation == UIImageOrientationDown) { 
     // NOTHING 
    } else if (orientation == UIImageOrientationUp) { 
     CGContextRotateCTM (context, radians(90)); 
    } 

    [src drawAtPoint:CGPointMake(0, 0)]; 

    return UIGraphicsGetImageFromCurrentImageContext(); 
} 

取自here

img.transform = CGAffineTransformMakeRotation(3.14159265/2);