Ios 为什么CGContextDrawImage会旋转我的图像

Ios 为什么CGContextDrawImage会旋转我的图像,ios,uiimage,cgcontext,Ios,Uiimage,Cgcontext,我正在尝试使用CGContext更改我的UIImage区域的颜色,然后从当前状态创建一个新图像。原始图像具有正确的方向,但在此之后,图像会转向侧面 CGRect imageRect = CGRectMake(0, 0, originalImage.size.width, originalImage.size.height); UIGraphicsBeginImageContextWithOptions(originalImage.size, false, originalImage.scal

我正在尝试使用
CGContext
更改我的
UIImage
区域的颜色,然后从当前状态创建一个新图像。原始图像具有正确的方向,但在此之后,图像会转向侧面

CGRect imageRect = CGRectMake(0, 0, originalImage.size.width, originalImage.size.height);

 UIGraphicsBeginImageContextWithOptions(originalImage.size, false, originalImage.scale);
 CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSaveGState(context);
CGContextDrawImage(context, imageRect, originalImage.CGImage);
CGContextSetRGBFillColor(context, 255.0f, 255.0f, 255.0f, 1.0f);
CGContextFillRect(context, CGRectMake(5,5,100,100));
CGContextRotateCTM (context, radians(270));
CGContextRestoreGState(context);
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();

这是一个非常简单的问题

因为iOS系统有3个不同的坐标系

UIKit-y轴方向向下 岩芯图形(石英)-y轴方向向上 OpenGL ES-y轴方向向上

原始图像是由UIKit创建的,目标图像是由核心图形创建的,因此应该是倒置的

如果要获得正确的图像,可以使用:

UIImageView* imageV = [[UIImageView alloc] initWithFrame:CGRectMake(100,100, 100, 100)];
imageV.layer.borderColor = [UIColor redColor].CGColor;
imageV.layer.borderWidth = 1;
imageV.image = img;
imageV.layer.transform = CATransform3DRotate(imageV.layer.transform, M_PI, 1.0f, 0.0f, 0.0f);
[self.view addSubview:imageV];
希望它能帮助你