Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 7th, 2012  |  syntax: None  |  size: 2.49 KB  |  hits: 6  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to use eraser before and after scaling of a image in objective-c iPhone?
  2. CGPoint translatedPoint = [(UIPanGestureRecognizer*)sender locationInView:tattooImage];
  3. if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateBegan)
  4. {
  5.      lastPoint = translatedPoint;
  6.      //lastPoint.x += 60;
  7.      //lastPoint.y += 60;
  8. }
  9. else
  10. {
  11.      CGPoint currentPoint = translatedPoint;
  12.      //currentPoint.x += 60;    
  13.      //currentPoint.y += 60;
  14.  
  15.      UIGraphicsBeginImageContext(tattooImage.frame.size);
  16.      [tattooImage.image drawInRect:CGRectMake(0, 0,tattooImage.frame.size.width, tattooImage.frame.size.height)];
  17.      CGContextSetBlendMode(UIGraphicsGetCurrentContext( ),kCGBlendModeClear);
  18.      CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
  19.      CGContextSetLineWidth(UIGraphicsGetCurrentContext( ), 25.0);
  20.  
  21.      CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(), [[UIColor clearColor] CGColor]);
  22.      CGContextBeginPath(UIGraphicsGetCurrentContext());
  23.      CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
  24.      CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
  25.      CGContextStrokePath(UIGraphicsGetCurrentContext()) ;
  26.  
  27.      tattooImage.image = UIGraphicsGetImageFromCurrentImageContext();
  28.      UIGraphicsEndImageContext();
  29.  
  30.      lastPoint = currentPoint;
  31. }
  32.        
  33. - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
  34. {
  35.  
  36.     mouseSwiped = YES;
  37.  
  38.     UITouch *touch = [[event touchesForView:imageView] anyObject];
  39.     CGPoint currentPoint = [touch locationInView:drawingView];
  40.  
  41.     UIGraphicsBeginImageContext(drawingView.frame.size);
  42.     [drawingView.image drawInRect:CGRectMake(0, 0, drawingView.frame.size.width, drawingView.frame.size.height)];
  43.     CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
  44.     CGContextSetLineWidth(UIGraphicsGetCurrentContext( ), 5.0);
  45.     if (eraserSelected)
  46.     {
  47.         CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeClear);
  48.         CGContextSetLineWidth(UIGraphicsGetCurrentContext( ), 10.0);
  49.     }
  50.     [self changeBrushColor];
  51.     CGContextBeginPath(UIGraphicsGetCurrentContext());
  52.     CGContextMoveToPoint(UIGraphicsGetCurrentContext() , lastPoint.x, lastPoint.y);
  53.     CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
  54.     CGContextStrokePath(UIGraphicsGetCurrentContext()) ;
  55.     drawingView.image = UIGraphicsGetImageFromCurrentImageContext();
  56.     UIGraphicsEndImageContext();
  57.  
  58.     lastPoint = currentPoint;  
  59.     }