如何旋转UIImage 90度?

如何旋转UIImage 90度?

我有一个UIImage那是UIImageOrientationUp(肖像)我想逆时针旋转90度(对景观)。我不想用CGAffineTransform..我要的像素UIImage移动位置。我使用的代码块(如下所示)最初是为了调整UIImage做这件事。我将目标大小设置为UIImage但我有个错误:

(错误):CGBitmapContextCreate:无效的数据字节/行:对于8个整数位/组件、3个组件、kCGImageAlphaPreMultiiedLast.应当至少为1708。

(当我提供一个较小的大小作为目标大小BTW时,我不会收到错误)。如何旋转我的UIImage90度CCW只使用核心图形功能,同时保持当前大小?

-(UIImage*)reverseImageByScalingToSize:(CGSize)targetSize:(UIImage*)anImage{
    UIImage* sourceImage = anImage; 
    CGFloat targetWidth = targetSize.height;
    CGFloat targetHeight = targetSize.width;

    CGImageRef imageRef = [sourceImage CGImage];
    CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(imageRef);
    CGColorSpaceRef colorSpaceInfo = CGImageGetColorSpace(imageRef);

    if (bitmapInfo == kCGImageAlphaNone) {
        bitmapInfo = kCGImageAlphaNoneSkipLast;
    }

    CGContextRef bitmap;

    if (sourceImage.imageOrientation == UIImageOrientationUp || sourceImage.imageOrientation == UIImageOrientationDown) {
        bitmap = CGBitmapContextCreate(NULL, targetHeight, targetWidth, CGImageGetBitsPerComponent(imageRef), 
        CGImageGetBytesPerRow(imageRef), colorSpaceInfo, bitmapInfo);

    } else {


        bitmap = CGBitmapContextCreate(NULL, targetWidth, targetHeight, CGImageGetBitsPerComponent(imageRef), 
        CGImageGetBytesPerRow(imageRef), colorSpaceInfo, bitmapInfo);

    }       


    if (sourceImage.imageOrientation == UIImageOrientationRight) {
        CGContextRotateCTM (bitmap, radians(90));
        CGContextTranslateCTM (bitmap, 0, -targetHeight);

    } else if (sourceImage.imageOrientation == UIImageOrientationLeft) {
        CGContextRotateCTM (bitmap, radians(-90));
        CGContextTranslateCTM (bitmap, -targetWidth, 0);

    } else if (sourceImage.imageOrientation == UIImageOrientationDown) {
        // NOTHING
    } else if (sourceImage.imageOrientation == UIImageOrientationUp) {
        CGContextRotateCTM (bitmap, radians(90));
        CGContextTranslateCTM (bitmap, 0, -targetHeight);
    }

 }


牛魔王的故事
浏览 1253回答 3
3回答

慕尼黑8549860

比如: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)];     UIImage *image = UIGraphicsGetImageFromCurrentImageContext();     UIGraphicsEndImageContext();     return image;}

忽然笑

我认为最简单的方法(也是线程安全)是这样做://assume that the image is loaded in landscape mode from diskUIImage * landscapeImage = [UIImage imageNamed:imgname]; UIImage * portraitImage = [[UIImage alloc] initWithCGImage: landscapeImage.CGImage                                                      scale: 1.0                                                orientation: UIImageOrientationRight];注:AS脑器说,这只是修改图像的方向数据-像素数据是未被触及的。对于某些应用程序来说,这可能还不够。或者在SWIFT:let portraitImage  : UIImage = UIImage(CGImage: landscapeImage.CGImage ,             scale: 1.0 ,             orientation: UIImageOrientation.Right)

慕侠2389804

请查看HardyMacia的简单和令人敬畏的代码:切割缩放旋转图像打电话UIImage&nbsp;*rotatedImage&nbsp;=&nbsp;[originalImage&nbsp;imageRotatedByDegrees:90.0];谢谢Hardy Macia!标题:(UIImage*)ImageAtRect:(CGRect)RECT;(UIImage*)imageByScalingProportionallyToMinimumSize:(CGSize)targetSize;)(UIImage*)imageByScalingProportionallyToSize:(CGSize)targetSize;)(UIImage*)ImageByScalingToSize:(CGSize)Target Size;(UIImage*)ImageRotatedByRadians:(CGFloat)弧度;(UIImage*)ImageRotatedByDegrees:(CGFloat)度;由于链接可能会失效,下面是完整的代码////&nbsp;&nbsp;UIImage-Extensions.h////&nbsp;&nbsp;Created&nbsp;by&nbsp;Hardy&nbsp;Macia&nbsp;on&nbsp;7/1/09.//&nbsp;&nbsp;Copyright&nbsp;2009&nbsp;Catamount&nbsp;Software.&nbsp;All&nbsp;rights&nbsp;reserved. //#import&nbsp;<Foundation/Foundation.h>#import&nbsp;<UIKit/UIKit.h>@interface&nbsp;UIImage&nbsp;(CS_Extensions)-&nbsp;(UIImage&nbsp;*)imageAtRect:(CGRect)rect; -&nbsp;(UIImage&nbsp;*)imageByScalingProportionallyToMinimumSize:(CGSize)targetSize;-&nbsp;(UIImage&nbsp;*)imageByScalingProportionallyToSize:(CGSize)targetSize; -&nbsp;(UIImage&nbsp;*)imageByScalingToSize:(CGSize)targetSize;-&nbsp;(UIImage&nbsp;*)imageRotatedByRadians:(CGFloat)radians;-&nbsp;(UIImage&nbsp;*)imageRotatedByDegrees: (CGFloat)degrees;@end;////&nbsp;&nbsp;UIImage-Extensions.m////&nbsp;&nbsp;Created&nbsp;by&nbsp;Hardy&nbsp;Macia&nbsp;on&nbsp;7/1/09. //&nbsp;&nbsp;Copyright&nbsp;2009&nbsp;Catamount&nbsp;Software.&nbsp;All&nbsp;rights&nbsp;reserved.//#import&nbsp;"UIImage-Extensions.h"CGFloat&nbsp;DegreesToRadians(CGFloat&nbsp;degrees)&nbsp; {return&nbsp;degrees&nbsp;*&nbsp;M_PI&nbsp;/&nbsp;180;};CGFloat&nbsp;RadiansToDegrees(CGFloat&nbsp;radians)&nbsp;{return&nbsp;radians&nbsp;*&nbsp;180/M_PI;};@implementation&nbsp;UIImage&nbsp;(CS_Extensions) -(UIImage&nbsp;*)imageAtRect:(CGRect)rect{ &nbsp;&nbsp;&nbsp;CGImageRef&nbsp;imageRef&nbsp;=&nbsp;CGImageCreateWithImageInRect([self&nbsp;CGImage],&nbsp;rect); &nbsp;&nbsp;&nbsp;UIImage*&nbsp;subImage&nbsp;=&nbsp;[UIImage&nbsp;imageWithCGImage:&nbsp;imageRef]; &nbsp;&nbsp;&nbsp;CGImageRelease(imageRef); &nbsp;&nbsp;&nbsp;return&nbsp;subImage;}-&nbsp;(UIImage&nbsp;*)imageByScalingProportionallyToMinimumSize:(CGSize)targetSize&nbsp;{ &nbsp;&nbsp;&nbsp;UIImage&nbsp;*sourceImage&nbsp;=&nbsp;self; &nbsp;&nbsp;&nbsp;UIImage&nbsp;*newImage&nbsp;=&nbsp;nil; &nbsp;&nbsp;&nbsp;CGSize&nbsp;imageSize&nbsp;=&nbsp;sourceImage.size; &nbsp;&nbsp;&nbsp;CGFloat&nbsp;width&nbsp;=&nbsp;imageSize.width; &nbsp;&nbsp;&nbsp;CGFloat&nbsp;height&nbsp;=&nbsp;imageSize.height; &nbsp;&nbsp;&nbsp;CGFloat&nbsp;targetWidth&nbsp;=&nbsp;targetSize.width; &nbsp;&nbsp;&nbsp;CGFloat&nbsp;targetHeight&nbsp;=&nbsp;targetSize.height; &nbsp;&nbsp;&nbsp;CGFloat&nbsp;scaleFactor&nbsp;=&nbsp;0.0; &nbsp;&nbsp;&nbsp;CGFloat&nbsp;scaledWidth&nbsp;=&nbsp;targetWidth; &nbsp;&nbsp;&nbsp;CGFloat&nbsp;scaledHeight&nbsp;=&nbsp;targetHeight; &nbsp;&nbsp;&nbsp;CGPoint&nbsp;thumbnailPoint&nbsp;=&nbsp;CGPointMake(0.0,0.0); &nbsp;&nbsp;&nbsp;if&nbsp;(CGSizeEqualToSize(imageSize,&nbsp;targetSize)&nbsp;==&nbsp;NO)&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CGFloat&nbsp;widthFactor&nbsp;=&nbsp;targetWidth&nbsp;/&nbsp;width; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CGFloat&nbsp;heightFactor&nbsp;=&nbsp;targetHeight&nbsp;/&nbsp;height; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(widthFactor&nbsp;>&nbsp;heightFactor)&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scaleFactor&nbsp;=&nbsp;widthFactor; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scaleFactor&nbsp;=&nbsp;heightFactor; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scaledWidth&nbsp;&nbsp;=&nbsp;width&nbsp;*&nbsp;scaleFactor; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scaledHeight&nbsp;=&nbsp;height&nbsp;*&nbsp;scaleFactor; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;center&nbsp;the&nbsp;image &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(widthFactor&nbsp;>&nbsp;heightFactor)&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;thumbnailPoint.y&nbsp;=&nbsp;(targetHeight&nbsp;-&nbsp;scaledHeight)&nbsp;*&nbsp;0.5;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;if&nbsp;(widthFactor&nbsp;<&nbsp;heightFactor)&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;thumbnailPoint.x&nbsp;=&nbsp;(targetWidth&nbsp;-&nbsp;scaledWidth)&nbsp;*&nbsp;0.5; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;//&nbsp;this&nbsp;is&nbsp;actually&nbsp;the&nbsp;interesting&nbsp;part: &nbsp;&nbsp;&nbsp;UIGraphicsBeginImageContext(targetSize); &nbsp;&nbsp;&nbsp;CGRect&nbsp;thumbnailRect&nbsp;=&nbsp;CGRectZero; &nbsp;&nbsp;&nbsp;thumbnailRect.origin&nbsp;=&nbsp;thumbnailPoint; &nbsp;&nbsp;&nbsp;thumbnailRect.size.width&nbsp;&nbsp;=&nbsp;scaledWidth; &nbsp;&nbsp;&nbsp;thumbnailRect.size.height&nbsp;=&nbsp;scaledHeight; &nbsp;&nbsp;&nbsp;[sourceImage&nbsp;drawInRect:thumbnailRect]; &nbsp;&nbsp;&nbsp;newImage&nbsp;=&nbsp;UIGraphicsGetImageFromCurrentImageContext(); &nbsp;&nbsp;&nbsp;UIGraphicsEndImageContext(); &nbsp;&nbsp;&nbsp;if(newImage&nbsp;==&nbsp;nil)&nbsp;NSLog(@"could&nbsp;not&nbsp;scale&nbsp;image"); &nbsp;&nbsp;&nbsp;return&nbsp;newImage&nbsp;;}-&nbsp;(UIImage&nbsp;*)imageByScalingProportionallyToSize:(CGSize)targetSize&nbsp;{ &nbsp;&nbsp;&nbsp;UIImage&nbsp;*sourceImage&nbsp;=&nbsp;self; &nbsp;&nbsp;&nbsp;UIImage&nbsp;*newImage&nbsp;=&nbsp;nil; &nbsp;&nbsp;&nbsp;CGSize&nbsp;imageSize&nbsp;=&nbsp;sourceImage.size; &nbsp;&nbsp;&nbsp;CGFloat&nbsp;width&nbsp;=&nbsp;imageSize.width; &nbsp;&nbsp;&nbsp;CGFloat&nbsp;height&nbsp;=&nbsp;imageSize.height; &nbsp;&nbsp;&nbsp;CGFloat&nbsp;targetWidth&nbsp;=&nbsp;targetSize.width; &nbsp;&nbsp;&nbsp;CGFloat&nbsp;targetHeight&nbsp;=&nbsp;targetSize.height; &nbsp;&nbsp;&nbsp;CGFloat&nbsp;scaleFactor&nbsp;=&nbsp;0.0; &nbsp;&nbsp;&nbsp;CGFloat&nbsp;scaledWidth&nbsp;=&nbsp;targetWidth; &nbsp;&nbsp;&nbsp;CGFloat&nbsp;scaledHeight&nbsp;=&nbsp;targetHeight; &nbsp;&nbsp;&nbsp;CGPoint&nbsp;thumbnailPoint&nbsp;=&nbsp;CGPointMake(0.0,0.0); &nbsp;&nbsp;&nbsp;if&nbsp;(CGSizeEqualToSize(imageSize,&nbsp;targetSize)&nbsp;==&nbsp;NO)&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CGFloat&nbsp;widthFactor&nbsp;=&nbsp;targetWidth&nbsp;/&nbsp;width; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CGFloat&nbsp;heightFactor&nbsp;=&nbsp;targetHeight&nbsp;/&nbsp;height; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(widthFactor&nbsp;<&nbsp;heightFactor)&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scaleFactor&nbsp;=&nbsp;widthFactor; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scaleFactor&nbsp;=&nbsp;heightFactor; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scaledWidth&nbsp;&nbsp;=&nbsp;width&nbsp;*&nbsp;scaleFactor; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scaledHeight&nbsp;=&nbsp;height&nbsp;*&nbsp;scaleFactor; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;center&nbsp;the&nbsp;image &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(widthFactor&nbsp;<&nbsp;heightFactor)&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;thumbnailPoint.y&nbsp;=&nbsp;(targetHeight&nbsp;-&nbsp;scaledHeight)&nbsp;*&nbsp;0.5;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;if&nbsp;(widthFactor&nbsp;>&nbsp;heightFactor)&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;thumbnailPoint.x&nbsp;=&nbsp;(targetWidth&nbsp;-&nbsp;scaledWidth)&nbsp;*&nbsp;0.5; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;//&nbsp;this&nbsp;is&nbsp;actually&nbsp;the&nbsp;interesting&nbsp;part: &nbsp;&nbsp;&nbsp;UIGraphicsBeginImageContext(targetSize); &nbsp;&nbsp;&nbsp;CGRect&nbsp;thumbnailRect&nbsp;=&nbsp;CGRectZero; &nbsp;&nbsp;&nbsp;thumbnailRect.origin&nbsp;=&nbsp;thumbnailPoint; &nbsp;&nbsp;&nbsp;thumbnailRect.size.width&nbsp;&nbsp;=&nbsp;scaledWidth; &nbsp;&nbsp;&nbsp;thumbnailRect.size.height&nbsp;=&nbsp;scaledHeight; &nbsp;&nbsp;&nbsp;[sourceImage&nbsp;drawInRect:thumbnailRect]; &nbsp;&nbsp;&nbsp;newImage&nbsp;=&nbsp;UIGraphicsGetImageFromCurrentImageContext(); &nbsp;&nbsp;&nbsp;UIGraphicsEndImageContext(); &nbsp;&nbsp;&nbsp;if(newImage&nbsp;==&nbsp;nil)&nbsp;NSLog(@"could&nbsp;not&nbsp;scale&nbsp;image"); &nbsp;&nbsp;&nbsp;return&nbsp;newImage&nbsp;;}-&nbsp;(UIImage&nbsp;*)imageByScalingToSize:(CGSize)targetSize&nbsp;{ &nbsp;&nbsp;&nbsp;UIImage&nbsp;*sourceImage&nbsp;=&nbsp;self; &nbsp;&nbsp;&nbsp;UIImage&nbsp;*newImage&nbsp;=&nbsp;nil; &nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp;CGSize&nbsp;imageSize&nbsp;=&nbsp;sourceImage.size; &nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp;CGFloat&nbsp;width&nbsp;=&nbsp;imageSize.width; &nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp;CGFloat&nbsp;height&nbsp;=&nbsp;imageSize.height; &nbsp;&nbsp;&nbsp;CGFloat&nbsp;targetWidth&nbsp;=&nbsp;targetSize.width; &nbsp;&nbsp;&nbsp;CGFloat&nbsp;targetHeight&nbsp;=&nbsp;targetSize.height; &nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp;CGFloat&nbsp;scaleFactor&nbsp;=&nbsp;0.0; &nbsp;&nbsp;&nbsp;CGFloat&nbsp;scaledWidth&nbsp;=&nbsp;targetWidth; &nbsp;&nbsp;&nbsp;CGFloat&nbsp;scaledHeight&nbsp;=&nbsp;targetHeight; &nbsp;&nbsp;&nbsp;CGPoint&nbsp;thumbnailPoint&nbsp;=&nbsp;CGPointMake(0.0,0.0); &nbsp;&nbsp;&nbsp;//&nbsp;this&nbsp;is&nbsp;actually&nbsp;the&nbsp;interesting&nbsp;part: &nbsp;&nbsp;&nbsp;UIGraphicsBeginImageContext(targetSize); &nbsp;&nbsp;&nbsp;CGRect&nbsp;thumbnailRect&nbsp;=&nbsp;CGRectZero; &nbsp;&nbsp;&nbsp;thumbnailRect.origin&nbsp;=&nbsp;thumbnailPoint; &nbsp;&nbsp;&nbsp;thumbnailRect.size.width&nbsp;&nbsp;=&nbsp;scaledWidth; &nbsp;&nbsp;&nbsp;thumbnailRect.size.height&nbsp;=&nbsp;scaledHeight; &nbsp;&nbsp;&nbsp;[sourceImage&nbsp;drawInRect:thumbnailRect]; &nbsp;&nbsp;&nbsp;newImage&nbsp;=&nbsp;UIGraphicsGetImageFromCurrentImageContext(); &nbsp;&nbsp;&nbsp;UIGraphicsEndImageContext(); &nbsp;&nbsp;&nbsp;if(newImage&nbsp;==&nbsp;nil)&nbsp;NSLog(@"could&nbsp;not&nbsp;scale&nbsp;image"); &nbsp;&nbsp;&nbsp;return&nbsp;newImage&nbsp;;}-&nbsp;(UIImage&nbsp;*)imageRotatedByRadians:(CGFloat)radians{ &nbsp;&nbsp;&nbsp;return&nbsp;[self&nbsp;imageRotatedByDegrees:RadiansToDegrees(radians)];}-&nbsp;(UIImage&nbsp;*)imageRotatedByDegrees:(CGFloat)degrees&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;//&nbsp;calculate&nbsp;the&nbsp;size&nbsp;of&nbsp;the&nbsp;rotated&nbsp;view's&nbsp;containing&nbsp;box&nbsp;for&nbsp;our&nbsp;drawing&nbsp;space &nbsp;&nbsp;&nbsp;UIView&nbsp;*rotatedViewBox&nbsp;=&nbsp;[[UIView&nbsp;alloc]&nbsp;initWithFrame:CGRectMake(0,0,self.size.width,&nbsp;self.size.height)]; &nbsp;&nbsp;&nbsp;CGAffineTransform&nbsp;t&nbsp;=&nbsp;CGAffineTransformMakeRotation(DegreesToRadians(degrees)); &nbsp;&nbsp;&nbsp;rotatedViewBox.transform&nbsp;=&nbsp;t; &nbsp;&nbsp;&nbsp;CGSize&nbsp;rotatedSize&nbsp;=&nbsp;rotatedViewBox.frame.size; &nbsp;&nbsp;&nbsp;[rotatedViewBox&nbsp;release]; &nbsp;&nbsp;&nbsp;//&nbsp;Create&nbsp;the&nbsp;bitmap&nbsp;context &nbsp;&nbsp;&nbsp;UIGraphicsBeginImageContext(rotatedSize); &nbsp;&nbsp;&nbsp;CGContextRef&nbsp;bitmap&nbsp;=&nbsp;UIGraphicsGetCurrentContext(); &nbsp;&nbsp;&nbsp;//&nbsp;Move&nbsp;the&nbsp;origin&nbsp;to&nbsp;the&nbsp;middle&nbsp;of&nbsp;the&nbsp;image&nbsp;so&nbsp;we&nbsp;will&nbsp;rotate&nbsp;and&nbsp;scale&nbsp;around&nbsp;the&nbsp;center. &nbsp;&nbsp;&nbsp;CGContextTranslateCTM(bitmap,&nbsp;rotatedSize.width/2,&nbsp;rotatedSize.height/2); &nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp;//&nbsp;Rotate&nbsp;the&nbsp;image&nbsp;context &nbsp;&nbsp;&nbsp;CGContextRotateCTM(bitmap,&nbsp;DegreesToRadians(degrees)); &nbsp;&nbsp;&nbsp;//&nbsp;Now,&nbsp;draw&nbsp;the&nbsp;rotated/scaled&nbsp;image&nbsp;into&nbsp;the&nbsp;context &nbsp;&nbsp;&nbsp;CGContextScaleCTM(bitmap,&nbsp;1.0,&nbsp;-1.0); &nbsp;&nbsp;&nbsp;CGContextDrawImage(bitmap,&nbsp;CGRectMake(-self.size.width&nbsp;/&nbsp;2,&nbsp;-self.size.height&nbsp;/&nbsp;2,&nbsp;self.size.width,&nbsp;self.size.height),&nbsp;[self&nbsp;CGImage]); &nbsp;&nbsp;&nbsp;UIImage&nbsp;*newImage&nbsp;=&nbsp;UIGraphicsGetImageFromCurrentImageContext(); &nbsp;&nbsp;&nbsp;UIGraphicsEndImageContext(); &nbsp;&nbsp;&nbsp;return&nbsp;newImage;}@end;分享
打开App,查看更多内容
随时随地看视频慕课网APP