CGContextRef旋转不起作用

时间:2012-09-22 08:05:22

标签: ios rotation core-graphics cgcontextref

我想用-90度旋转CGContextRef的内容。 我发现了一些代码,但它无法正常工作。

CGContextRef tempColorRef = CGBitmapContextCreate(NULL, width, height, bitsPerComponent,
                                                  bytesPerRow, colorspace,
                                                  kCGImageAlphaPremultipliedLast);
CGImageRef colorImageRef = CGBitmapContextCreateImage(colorContextRef);
CGContextTranslateCTM(tempLayerRef, width / 2, height / 2);
CGContextRotateCTM(tempLayerRef, DegreesToRadians(-90));
CGContextScaleCTM(tempColorRef, 1.0, -1.0);
CGContextDrawImage(tempColorRef, CGRectMake(-width / 2, -height / 2, width, height), colorImageRef);
CGImageRelease(colorImageRef);

colorContextRef = tempColorRef;

任何人都会帮助我。

1 个答案:

答案 0 :(得分:0)

根据H2CO3的评论,我尝试了各种转换。

这是我的错。 widthheightsize_t个变量,因此这些变量不能保持负值。错误发生在以下说明中。

CGRectMake(-width / 2, -height / 2, width, height)

现在工作正常。

相关问题