0

コア グラフィックスを使用して、中心に向かってアルファ値が増加する羽の付いた円をどのように描画しますか? このようなもの:

ここに画像の説明を入力

理想的には、色、円の半径、およびアルファ強度がパラメーターになります。

4

2 に答える 2

2

これは、私のアプリのいくつかでうまくいきました。柔らかさは 0 ~ 1 です。幅 (正方形) の幅と高さで CGBitmapContext を自分で作成する必要があります。

// make a path:
self.shapePath = CGPathCreateMutable();
CGPathAddEllipseInRect(self.shapePath, NULL, CGRectMake(0, 0, width, width));
CGFloat radius = width / 2.0f;        
NSInteger innerRadius = (softness < 0.01f ? (NSInteger)radius : (NSInteger)ceil((1.0f - softness) * radius));
NSInteger outerRadius = (NSInteger)ceil(radius);
CGFloat alphaStep = MAX(0.0059f, (1.0f / ((outerRadius - innerRadius) + 1)));
CGFloat outerMultiplier = 1.0f / (2.0f * (CGFloat)outerRadius);

for (NSInteger i = outerRadius; i >= innerRadius; --i)
{
    CGContextSaveGState(bitmapContext);
    UIColor* c = [UIColor.whiteColor colorWithAlphaComponent:alphaStep];
    CGContextTranslateCTM(bitmapContext, outerRadius - i, outerRadius - i);
    CGFloat scale = (2.0f * (CGFloat)i) * outerMultiplier;
    CGContextScaleCTM(bitmapContext, scale, scale);
    CGContextSetFillColorWithColor(bitmapContext, c.CGColor);
    CGContextAddPath(bitmapContext, self.shapePath);
    CGContextEOFillPath(bitmapContext);
    CGContextRestoreGState(bitmapContext);
}
于 2013-11-12T22:33:18.763 に答える
1

Core GraphicsCGGradientRefCGContextDrawRadialGradient() 関数を使用するか、Core 画像CIRadialGradientフィルターを使用できます。どちらを使用するかは、ニーズによって異なります。

于 2013-11-12T22:02:18.060 に答える