3

CGcontext を使用して画像を作成したい。これは、白または黒の背景のシンプルなイメージです。また、丸の中にある透明部分を追加したいです(添付画像を確認してください)。私はrectでこれを行う方法を知っています。でも丸くしたい。誰でもこれで私を助けてください。 ここに画像の説明を入力

4

1 に答える 1

4

以下のコードを使用して、コンテキスト内の円をクリアします

-(UIImage *) getImageWithcenterClear:(CGPoint) center{

    CGRect frame = [[UIScreen mainScreen] bounds];

    UIGraphicsBeginImageContextWithOptions([[UIScreen mainScreen] bounds].size,
                                       NO, [UIScreen mainScreen].scale);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [[UIColor colorWithRed:0 green:0 blue:0 alpha:0.5 ] CGColor]);
    CGContextFillRect(context, frame);

    float radius = 50 * 2;
    // Clear Circle

    CGContextSetFillColorWithColor(context, [UIColor clearColor].CGColor);
    CGContextSetBlendMode(context, kCGBlendModeClear);
    CGContextAddArc(context, center.x, center.y, radius - 0.54, 0, 2 * M_PI, 0);
    CGContextDrawPath(context, kCGPathFill);
    CGContextSetBlendMode(context, kCGBlendModeNormal);

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return image;

}
于 2015-11-07T09:36:39.313 に答える