XMG Quartz2D 图片擦除

实现的效果 擦除图片的模糊的地方清晰的地方显示出来

  • 第一步
    创建位图上下文对象
  • 第二步
    把外面的图片渲染到位图上下文对象上
  • 第三步
    清除手指选定的区域 。清除后那部分变为透明。下面的部分显示出来
  • 第四步
    把上下文得到的剩余的图片得到,然后给imgeView赋值

  • 第五步
    关闭上下文对象

源码如下


    - (void)pan:(UIPanGestureRecognizer *)pan
{
    CGFloat squareW=30;
    CGPoint currentP=[pan locationInView:self.view];
    CGFloat pointX=currentP.x-squareW/2;
    CGFloat pointY=currentP.y-squareW/2;
    CGRect rect=CGRectMake(pointX, pointY, squareW, squareW);
    //创建位图上下文
    UIGraphicsBeginImageContextWithOptions(self.imageView.frame.size, NO, 0);
    //贝泽尔曲线
//    UIBezierPath*path=[UIBezierPath bezierPathWithRect:rect];
    CGContextRef context=UIGraphicsGetCurrentContext();
    [self.imageView.layer renderInContext:context];
    //清除部分
    CGContextClearRect(context, rect);

    self.imageView.image=UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值