我使用标准代码来旋转图像,但是当UIImageRotatation不等于2时,图像旋转不正确。
修复UIImageRotation并将图像旋转X度的任何代码?几乎尝试一切。
NSLog(@"Image orientation %d",self.imageOrientation);
CGSize rotatedSize = CGSizeApplyAffineTransform(self.size, CGAffineTransformMakeRotation(rad(degrees)));
if (rotatedSize.width < 0) {
rotatedSize.width *= -1;
}
if (rotatedSize.height < 0) {
rotatedSize.height *= -1;
}
// Create the bitmap context
UIGraphicsBeginImageContextWithOptions(rotatedSize, YES, 0.0);
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, rad(degrees));
// Now, draw the rotated/scaled image into the context
CGContextScaleCTM(bitmap, 1.0, -1.0);
CGContextDrawImage(bitmap, CGRectMake(-self.size.width / 2, -self.size.height / 2, self.size.width, self.size.height), [self CGImage]);
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;