0

我有以下代码

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

问题是旋转发生在左下角,当它围绕中心计算时。有没有办法改变这个?

4

1 回答 1

1

您的代码在旋转矩阵之前对其进行平移。尝试将呼叫翻转到,CGContextConcatCTM然后CGContextTranslateCTM先轮换。或者,也许您正在寻找其他东西?

于 2009-11-18T07:35:53.647 回答