0

我正在使用标准代码来旋转图像,但是当 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;
4

0 回答 0