簡體   English   中英

如何在iOS中的CGContext中清除圓圈

[英]How to clear circle in CGContext in iOS

我想用CGcontext創建圖像。 這是簡單的圖象有白色或黑背景。 我也想添加圈內的transperent部分(查看附圖)。 我知道如何在rect中執行此操作。 但我想讓它圈出來。 請有人幫我這個。 在此輸入圖像描述

使用以下代碼清除上下文中的圓圈

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

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM