2009-11-18 42 views
0

我有以下代碼UIImage的轉動偏移

- (void)ComputeRotationWithRadians:(CGFloat)rad { 
    CGFloat width = exportImage.size.width; 
    CGFloat height = exportImage.size.height; 
    UIGraphicsBeginImageContext(CGSizeMake(width, height)); 
    CGContextRef ctxt = UIGraphicsGetCurrentContext(); 
    CGContextScaleCTM(ctxt, 1.0, -1.0); 
    CGContextTranslateCTM(ctxt, 0.0, -exportImage.size.height); 
    CGContextRotateCTM(ctxt, rad); 
    CGContextDrawImage(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, width, height), exportImage.CGImage); 
    exportImage = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
    [imageView setImage:exportImage]; 
} 

的問題是發生了旋轉圍繞左下角,當它已經圍繞中心計算。無論如何要改變這個?

回答

1

您的代碼在旋轉之前先轉換矩陣。嘗試翻轉電話CGContextConcatCTMCGContextTranslateCTM,讓您先旋轉。或者你正在尋找別的東西?

+0

我已更改代碼,請參閱上文,仍然無效 – woody993 2009-11-18 07:43:55

+0

您在旋轉之前仍在翻譯。您需要調用CGContextRotateCTM,然後調用CGContextTranslateCTM。 – fbrereto 2009-11-18 08:01:39

+0

現在它只是在左上角做它 – woody993 2009-11-18 10:21:39