保存为PNG之前,将新创build的iOS图像旋转90度

我已经阅读了许多与此有关的答案,但是我仍然无法得到它的工作。

我有一个用户可以签名的视图。 以下是它的外观: http : //d.pr/i/McuE

我可以成功检索这个图像并将其保存到文件系统,但是我需要将它旋转90度,然后保存,以便从左到右读取签名。

// Grab the image UIGraphicsBeginImageContext(self.signArea.bounds.size); [self.signArea drawRect: self.signArea.bounds]; UIImage *signatureImage = UIGraphicsGetImageFromCurrentImageContext(); //-- ? -- Rotate the image (this doesn't work) -- ? -- CGContextRef context = UIGraphicsGetCurrentContext(); CGContextRotateCTM(context, M_PI_2); UIGraphicsEndImageContext(); //Save the image as a PNG in Documents folder [UIImagePNGRepresentation(signatureImage) writeToFile:[[PPHelpers documentsPath] stringByAppendingPathComponent:@"signature-temp.png"] atomically:YES]; 

如何在保存之前旋转图像?

在此先感谢您的帮助。 我在使用iOS 7 SDK的Xcode 5上。

我终于得到这个工作使用这个职位上的答案之一: 如何旋转UIImage 90度?

我用这个方法:

 - (UIImage *)imageRotatedByDegrees:(UIImage*)oldImage deg:(CGFloat)degrees{ //Calculate the size of the rotated view's containing box for our drawing space UIView *rotatedViewBox = [[UIView alloc] initWithFrame:CGRectMake(0,0,oldImage.size.width, oldImage.size.height)]; CGAffineTransform t = CGAffineTransformMakeRotation(degrees * M_PI / 180); rotatedViewBox.transform = t; CGSize rotatedSize = rotatedViewBox.frame.size; //Create the bitmap context UIGraphicsBeginImageContext(rotatedSize); CGContextRef bitmap = UIGraphicsGetCurrentContext(); //Move the origin to the middle of the image so we will rotate and scale around the center. CGContextTranslateCTM(bitmap, rotatedSize.width/2, rotatedSize.height/2); //Rotate the image context CGContextRotateCTM(bitmap, (degrees * M_PI / 180)); //Now, draw the rotated/scaled image into the context CGContextScaleCTM(bitmap, 1.0, -1.0); CGContextDrawImage(bitmap, CGRectMake(-oldImage.size.width / 2, -oldImage.size.height / 2, oldImage.size.width, oldImage.size.height), [oldImage CGImage]); UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return newImage; } 

然后像这样调用它:

 //Rotate it UIImage *rotatedImage = [self imageRotatedByDegrees:signatureImage deg:90]; 

感谢大家。