重なり合う異なる色の同じ形状に描画するときに問題があります。アンチエイリアシングを有効にすると、生成された透明ピクセルがにじみ、この画像のようにアーティファクトが発生します。彼女が赤い円を描き、青い三角形を描き、次に赤い三角形を描くシーケンス。
この問題は、アンチエイリアシングを無効にすることで解決できますが、結果はぎざぎざのエッジになります。
たとえば、グラフィック コンテキストをさかのぼってアンチエイリアスしたり、画像にレンダリングしてその画像にアンチエイリアスを適用したりできるソリューションはありますか。または、鮮明なエッジで重なり合う形状を描くのに役立つその他のもの。
問題を再現するコードは次のとおりです
-(void)drawRect:(CGRect)rect
{
CGContextRef currentContext = UIGraphicsGetCurrentContext();
CGContextClearRect(currentContext, rect);
CGContextSetAllowsAntialiasing(currentContext, YES);
//// Color Declarations
UIColor* color = [UIColor redColor];
UIColor* color2= [UIColor blueColor];
//// Oval Drawing
UIBezierPath* ovalPath = [UIBezierPath bezierPathWithOvalInRect: rect];
[color setFill];
[ovalPath fill];
//// triangle Drawing
UIBezierPath* trianglePath = [UIBezierPath bezierPath];
[trianglePath moveToPoint: CGPointMake(0, 0)];
[trianglePath addLineToPoint: CGPointMake(rect.size.width, rect.size.height)];
[trianglePath addLineToPoint: CGPointMake(0, rect.size.height)];
[trianglePath addLineToPoint: CGPointMake(0, 0)];
[trianglePath closePath];
[color2 setFill];
[trianglePath fill];
[color setFill];
[trianglePath fill];
}