I am working on some image processing project where I need to implement eraser on a image. I have to also implement pinch effect to scale the image smaller or larger. Pinch is working nice. Eraser also works perfect If I dont scale the image by pinch. But when I use pinch and then use eraser. The image goes blur. I have implemented eraser on UIPanGestureRecognizer.
Below is the code for eraser.
CGPoint translatedPoint = [(UIPanGestureRecognizer*)sender locationInView:tattooImage];
if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateBegan)
{
lastPoint = translatedPoint;
//lastPoint.x += 60;
//lastPoint.y += 60;
}
else
{
CGPoint currentPoint = translatedPoint;
//currentPoint.x += 60;
//currentPoint.y += 60;
UIGraphicsBeginImageContext(tattooImage.frame.size);
[tattooImage.image drawInRect:CGRectMake(0, 0,tattooImage.frame.size.width, tattooImage.frame.size.height)];
CGContextSetBlendMode(UIGraphicsGetCurrentContext( ),kCGBlendModeClear);
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext( ), 25.0);
CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(), [[UIColor clearColor] CGColor]);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext()) ;
tattooImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
lastPoint = currentPoint;
}
Please provide any help. Thanks in advance.
I found the solution. There is a small change which I did and I got the desired result. I changed
tattooImage.frame.sizewithtattooImage.bounds.sizeeverywhere in the code, and It worked perfectly. Thanks to https://stackoverflow.com/users/1389202/pete-c