title: Best way to erase on a picture in Swift?
body: <p>I'm trying to make an app where I can <strong>erase the background from a picture</strong> that the user imports from <em>"Camera roll"</em>. <br>
  So i was thinking of hand drawing a UIColor.clearColor on the UIImage. 
  So i tried using Core Graphics to draw on my UIImage.<br>
  I tried initially to draw lines by:</p>
  
  <pre><code>override func touchesBegan(touches: Set&lt;UITouch&gt;, withEvent event: UIEvent?) {
      if let touch = touches.first {
          lastPoint = touch.locationInView(self)
      }
  }
  
  override func touchesMoved(touches: Set&lt;UITouch&gt;, withEvent event: UIEvent?) {
      if let touch = touches.first {
          var newPoint = touch.locationInView(self)
          lines.append(Line(start: lastPoint, end: newPoint))
          lastPoint = newPoint
          self.setNeedsDisplay()
      }
  }
  
  override func drawRect(rect: CGRect) {
      imageToSend.drawAtPoint(CGPointZero)
      var context = UIGraphicsGetCurrentContext()
      CGContextBeginPath(context)
      for line in lines {
          CGContextMoveToPoint(context, line.start.x, line.start.y)
          CGContextAddLineToPoint(context, line.end.x, line.end.y)
      }
      CGContextSetStrokeColorWithColor(context, UIColor.redColor().CGColor) //tried with a red color here
      CGContextSetLineWidth(context, 80.0)
      CGContextSetLineCap(context, .Round)
  }
  </code></pre>
  
  <p><strong>The problem is that it was very laggy.</strong> The memory usage in <em>Debug Session</em> (of xCode) was very high as well as the CPU Usage. <br>
  Running the app on iPhone 6s.<br>
  So is there a better way to erase on a picture in Swift? <br>
  Another problem is that it creates lines, I would like it to be more smooth. But that's another problem</p>