UIImage旋转偏移

时间:2009-11-18 07:31:48

标签: iphone uiimage rotation quartz-2d offset

我有以下代码

- (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 个答案:

答案 0 :(得分:1)

您的代码在旋转矩阵之前正在翻译矩阵。尝试将来电翻转到CGContextConcatCTMCGContextTranslateCTM,以便先轮换。或者也许你正在寻找别的东西?