2012-09-22 75 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)

它現在工作的罰款。