0

我有这个代码来为内部和外部边界之间的区域着色。

CGContextSaveGState(context);
CGContextAddRect(context, self.bounds);
CGContextAddPath(context, inlinePath);
CGContextEOClip(context);
CGContextAddPath(context, outlinePath);
CGContextClip(context);
CGContextSetFillColorWithColor(context, _myColor.CGColor);
CGContextFillRect(context, self.bounds);
CGContextRestoreGState(context);

这是当地例行公事的一部分drawChartInContext:
当我生成这样的图像时效果很好:

UIGraphicsBeginImageContextWithOptions(self.frame.size, NO, 2.0);
[self drawChartInContext:UIGraphicsGetCurrentContext()]; 
UIImage* image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

但是当我调用它时,drawRect我只会让整个outlinePath区域充满_myColor.

- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    [self drawChartInContext:context];
}

有什么问题?

4

1 回答 1

0

刚刚想通了。这是两个疏忽的结合:

  1. inlinePath面积为零(有效的特殊情况)
  2. myColor有 1.0 alpha(配置错误)。
于 2012-11-01T13:35:28.147 回答