I want to make eraser functionality in my image editing application
If i set eraser opacity with 0.5 then where i move the eraser that portion of image reduce the opacity with eraser opacity
i tried below code for that but no success on this
UIImage *img_BG = self.imgEdit;
CGSize size = img_BG.size;
CGRect area_BG = CGRectMake(0, 0, size.width, size.height);
UIImageView imgvw = (UIImageView *)self.contentView;
CGFloat ox = (img_BG.size.width * self.touchStart.x) / imgvw.frame.size.width;
CGFloat oy = (img_BG.size.height * self.touchStart.y) / imgvw.frame.size.height;
CGFloat nx = (img_BG.size.width * currentPoint.x) / imgvw.frame.size.width;
CGFloat ny = (img_BG.size.height * currentPoint.y) / imgvw.frame.size.height;
CGColorRef strokeColor = [UIColor whiteColor].CGColor;
UIGraphicsBeginImageContext(img_BG.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[img_BG drawInRect:area_BG];;
CGContextSetLineCap(context, kCGLineCapRound);
CGContextSetLineWidth(context, self.actualSizeEraser);
if (self.erraserMode == ZDEraserModeRestore) {
CGContextSetStrokeColorWithColor(context, [UIColor colorWithPatternImage:self.imgOriginal].CGColor);
}
else {
CGContextSetStrokeColorWithColor(context, strokeColor);
CGContextSetBlendMode(context, kCGBlendModeClear);
}
CGContextBeginPath(context);
CGContextMoveToPoint(context, ox, oy);
CGContextAddLineToPoint(context, nx, ny);
CGContextStrokePath(context);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
And One more thing i want to set that when i select eraser and move on then edge of edge of erased line will be soft like some blur effect
How i can achieve this?
If anyone provide solution with swift code that is also acceptable