2010-08-13 4 views
1

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

안녕하세요, 저는 이미지 중심점에서 UIImage를 회전시키지 않을 것입니다. 나는이 코드로 UIImage를 회전시킬 수 있지만 중심점에서는 회전시킬 수 없다.이미지 센터에서 UIImage를 회전하는 방법

도와주세요.

답변

2

코어 애니메이션을 사용하십시오. 당신은 말할 수있다

UIView.layer.anchor = aPoint;

그런 다음 CA 프레임 워크를 사용하여 회전을 수행하면 해당 앵커 주위에서 발생합니다.

0

이 코드는 있지만 UIImageOrientation = 0 작동

// 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]); 
관련 문제