Quartz2D之图片擦除

图片擦除

    // 获取当前点
    CGPoint curP = [pan locationInView:self.view];

    // 获取擦除的矩形范围
    CGFloat wh = 100;
    CGFloat x = curP.x - wh * 0.5;
    CGFloat y = curP.y - wh * 0.5;

    CGRect rect = CGRectMake(x, y, wh, wh);

    // 开启上下文
    UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, 0);

    CGContextRef ctx = UIGraphicsGetCurrentContext();

    // 控件的layer渲染上去
    [_imageView.layer renderInContext:ctx];

    // 擦除图片
    CGContextClearRect(ctx, rect);

    // 生成一张图片
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

    _imageView.image = image;

    // 关闭上下文
    UIGraphicsEndImageContext();

你可能感兴趣的:(Quartz2D之图片擦除)