- How to use eraser before and after scaling of a image in objective-c iPhone?
- 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;
- }
- - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
- {
- mouseSwiped = YES;
- UITouch *touch = [[event touchesForView:imageView] anyObject];
- CGPoint currentPoint = [touch locationInView:drawingView];
- UIGraphicsBeginImageContext(drawingView.frame.size);
- [drawingView.image drawInRect:CGRectMake(0, 0, drawingView.frame.size.width, drawingView.frame.size.height)];
- CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
- CGContextSetLineWidth(UIGraphicsGetCurrentContext( ), 5.0);
- if (eraserSelected)
- {
- CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeClear);
- CGContextSetLineWidth(UIGraphicsGetCurrentContext( ), 10.0);
- }
- [self changeBrushColor];
- CGContextBeginPath(UIGraphicsGetCurrentContext());
- CGContextMoveToPoint(UIGraphicsGetCurrentContext() , lastPoint.x, lastPoint.y);
- CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
- CGContextStrokePath(UIGraphicsGetCurrentContext()) ;
- drawingView.image = UIGraphicsGetImageFromCurrentImageContext();
- UIGraphicsEndImageContext();
- lastPoint = currentPoint;
- }