0

I have this code to color an area between an inside and outside boundary.

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);

This is part of a local routine drawChartInContext:.
It works great when I generate an image like this:

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

But when I call it from drawRect I just get the whole outlinePath area filled with _myColor.

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

What could be wrong?

4

1 に答える 1

0

ちょうどそれを理解しました。それは2つの見落としの組み合わせでした:

  1. inlinePath面積がゼロでした(有効な特殊なケース)
  2. myColor1.0アルファ(構成ミス)がありました。
于 2012-11-01T13:35:28.147 に答える