Search code examples
iosswiftxcodeuiimagecrop

How to remove area of UIImage where user move his finger?


  • IMAGECROPPER
  • UIGESTURE
  • TOUCH

Needed to achieve this, User selects Image and then cut it with Touch drag like Photo Editing App.

enter image description here


Solution

  •          UIGraphicsBeginImageContext(drawImage.frame.size)
                var context = UIGraphicsGetCurrentContext()
    
                drawImage.image.draw(in: CGRect(x: 0, y: 0, width: view.frame.size.width, height: view.frame.size.height - 50))
    
                context?.move(to: fromPoint)
                context?.addLine(to: toPoint)
                context?.setLineCap(.butt)
                context?.setLineWidth(2)
                context?.setBlendMode(.clear)
                context?.setShouldAntialias(true)
    
                UIColor.clear.set()
    
                context?.strokePath()
    
                let newImage = UIGraphicsGetImageFromCurrentImageContext()!