【发布时间】:2011-10-28 17:24:49
【问题描述】:
/* Adding the Path */
UserGraphBuff = UIGraphicsGetCurrentContext();
CGContextSetRGBStrokeColor(UserGraphBuff,5,10,0,1);
CGContextSetLineWidth(UserGraphBuff, 2 );
CGContextBeginPath(UserGraphBuff);
//line to last user point
CGContextAddLineToPoint(UserGraphBuff, (*xVal)[sizeof xVal / sizeof *xVal - 1], (*yNewVal)[sizeof yNewVal / sizeof *yNewVal - 1]);
//line to rest of user points in reverse order
for (int i = sizeof xVal / sizeof *xVal - 1; i > -1; i--){
CGContextAddLineToPoint(UserGraphBuff, (*xVal)[i], (*yNewVal)[i]);
}
//EOFill
CGContextEOFillPath(UserGraphBuff);
以上是我正在尝试解决的代码。它应该按照 CGContext 所说的去做,但我没有画出任何东西。 我不断收到此错误:
Fri Oct 28 13:18:40 case.app testApplication[4127] <Error>: CGContextSetRGBStrokeColor: invalid context 0x0
Fri Oct 28 13:18:40 case.app testApplication[4127] <Error>: CGContextSetLineWidth: invalid context 0x0
Fri Oct 28 13:18:40 case.app testApplication[4127] <Error>: CGContextBeginPath: invalid context 0x0
Fri Oct 28 13:18:40 case.app testApplication[4127] <Error>: CGContextAddLineToPoint: invalid context 0x0
Fri Oct 28 13:18:40 case.app testApplication[4127] <Error>: CGContextDrawPath: invalid context 0x0
我在头文件中引用了 CGContextRef。
我认为我对 CGContext 的理解不够好,也不知道 CGContextRef 应该是什么。
【问题讨论】:
-
这段代码在哪里?在
UIView子类的drawRect中? -
那是什么鬼?它有什么作用?是
-drawRect:调用的吗?
标签: cocoa-touch quartz-2d cgcontext