Iphone 如何在图像中心旋转UIImage

Iphone 如何在图像中心旋转UIImage,iphone,uiimage,Iphone,Uiimage,嗨,我习惯于在图像中心点旋转UIImage。我可以用这段代码旋转UIImage,但不能在中心点旋转 请帮助我。使用核心动画。你可以说 UIView.layer.anchor=aPoint 然后,使用CA框架进行旋转,旋转将围绕该锚点进行。此代码将起作用,但仅当UIImageOrientation=0时 //将原点移到图像的中间,以便我们围绕中心旋转和缩放。 CGContextTranslateCm(位图,rotatedSize.width/2,rotatedSize.height/2); //旋

嗨,我习惯于在图像中心点旋转UIImage。我可以用这段代码旋转UIImage,但不能在中心点旋转


请帮助我。

使用核心动画。你可以说

UIView.layer.anchor=aPoint


然后,使用CA框架进行旋转,旋转将围绕该锚点进行。

此代码将起作用,但仅当UIImageOrientation=0时

//将原点移到图像的中间,以便我们围绕中心旋转和缩放。
CGContextTranslateCm(位图,rotatedSize.width/2,rotatedSize.height/2);
//旋转图像上下文
CGContextRotateCTM(位图,rad(度));
//现在,将旋转/缩放图像绘制到上下文中
CGContextScaleCTM(位图,1.0,-1.0);
CGContextDrawImage(位图,CGRectMake(-self.size.width/2,-self.size.height/2,self.size.width,self.size.height),[self-CGImage]);

double angle = -15;
UIImage *image = [UIImage imageNamed:@"test.jpg"];
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();