2012-09-22 85 views
0

我想用-90度旋转CGContextRef的内容。 我发现了一些代码,但它无法正常工作。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; 

任何人都可以帮助我。

+2

“不能正常工作”是什么意思?你遇到鼻子恶魔还是什么? – 2012-09-22 08:30:38

+0

内容已经消失。 –

+0

我敢肯定,数学部分是搞砸了,你正在绘制*在上下文之外。如果你移除秤部分会怎么样? – 2012-09-22 10:13:06

回答

0

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

这是我的错。 widthheight分别是size_t变量,所以这些不能保持负值。错误发生在下面的指令中。

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

它现在工作的罚款。