0

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

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;

请任何人帮助我。

4

1 回答 1

0

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

这是我的错。width并且heightsize_t变量,所以这些不能包含负值。错误发生在以下说明中。

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

现在工作正常。

于 2012-09-25T08:19:55.323 回答