2

重なり合う異なる色の同じ形状に描画するときに問題があります。アンチエイリアシングを有効にすると、生成された透明ピクセルがにじみ、この画像のようにアーティファクトが発生します。彼女が赤い円を描き、青い三角形を描き、次に赤い三角形を描くシーケンス。

この問題は、アンチエイリアシングを無効にすることで解決できますが、結果はぎざぎざのエッジになります。

たとえば、グラフィック コンテキストをさかのぼってアンチエイリアスしたり、画像にレンダリングしてその画像にアンチエイリアスを適用したりできるソリューションはありますか。または、鮮明なエッジで重なり合う形状を描くのに役立つその他のもの。

問題を再現するコードは次のとおりです

-(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];
}
4

1 に答える 1

1

問題は、drawRect を使用すると、基本的に画像上に描画し、各描画メソッドが前の描画メソッドの上にレンダリングされることです。間引きはありません。

この問題を本当に解決するには、レンダリング パスが 1 つしかない OpenGL を使用することをお勧めします。そのため、非表示のオブジェクトはレンダリングされません。

于 2013-03-29T13:46:36.600 に答える