实现的效果 擦除图片的模糊的地方清晰的地方显示出来
- 第一步
创建位图上下文对象 - 第二步
把外面的图片渲染到位图上下文对象上 - 第三步
清除手指选定的区域 。清除后那部分变为透明。下面的部分显示出来 第四步
把上下文得到的剩余的图片得到,然后给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();
}