2016-08-02 3 views
-1

UIImage의 영역 색상을 CGContext으로 변경하려고하고 있으며 현재 상태에서 새 이미지를 만듭니다. 원본 이미지의 방향이 올바르지 만 이미지가 옆으로 바뀝니다.CGContextDrawImage가 내 이미지를 회전하는 이유

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(); 

답변

0

매우 쉬운 질문입니다.

iOS 시스템에는 3 개의 다른 좌표 시스템이 있기 때문에.

UIKit - Y 축 방향 최대 는 OpenGL ES이다 - - Y 축 방향은 가입 originalImage는 UIKit 의해 작성 대상 화상이 코어에 의해 생성이다

인 Y 축 방향 아래 코어 그래픽 (쿼츠)이다 그래픽, 거꾸로되어야합니다. 올바른 이미지를 얻을하려는 경우

, 당신은 사용할 수 있습니다

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]; 

가 당신을 도울 수 있기를 바랍니다.

관련 문제