我想要以自定义度数旋转UIImage(而不是UIImageView)。我遵循了this post,但对我没用。
有人可以帮忙吗?谢谢。
更新: 下面的代码完成了部分工作,但在旋转后我失去了一些图像:
有人可以帮忙吗?谢谢。
更新: 下面的代码完成了部分工作,但在旋转后我失去了一些图像:
- (UIImage *) rotate: (UIImage *) image
{
double angle = 20;
CGSize s = {image.size.width, image.size.height};
UIGraphicsBeginImageContext(s);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(ctx, 0,image.size.height);
CGContextScaleCTM(ctx, 1.0, -1.0);
CGContextRotateCTM(ctx, 2*M_PI*angle/360);
CGContextDrawImage(ctx,CGRectMake(0,0,image.size.width, image.size.height),image.CGImage);
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}