title: How to crop a zoomed Image in a circular hole with swift
body: <p>I am taking picture with camera in my app. I have a layer on top of my image view with a transparent hole as shown in the figure
  <a href="https://i.stack.imgur.com/PWfVM.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PWfVM.jpg" alt="enter image description here"></a></p>
  
  <p>What I want to do is crop the image in that circular hole. I am using that code but it is not working </p>
  
  <pre><code>UIGraphicsBeginImageContextWithOptions(CGSize(width: radius-60, height: radius-60),false,0)
  final!.draw(at: CGPoint(x: 30, y: screenHeight/2 - radius/2 + 30)
  let tmpImg = UIGraphicsGetImageFromCurrentImageContext()
  UIGraphicsEndImageContext()
  </code></pre>
  
  <p>where the height and width in UIGraphicsBeginImageContextWithOptions are the height and width of the circular hole and x and y in draw are the x coordinate of the hole and y coordinate is the upper boundary of the hole</p>
  
  <p><strong>Code For image</strong></p>
  
  <pre><code>func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
      print("here123")
      let image = info[UIImagePickerControllerOriginalImage] as! UIImage
      imageView.contentMode = .scaleAspectFit
      imageView.image = image
      self.view.backgroundColor = UIColor.black
      picker.dismiss(animated: true, completion: nil)
      photoSave()
  }
  </code></pre>
  
  <p><strong>Code for transparent hole</strong></p>
  
  <pre><code>screenWidth = self.view.frame.width
  screenHeight = self.view.frame.height 
  radius = min(screenWidth,screenHeight)
  let path = UIBezierPath(roundedRect: CGRect(x: 0, y: 0, width: screenWidth, height: screenHeight), cornerRadius: 0)
  let circlePath = UIBezierPath(roundedRect: CGRect(x: 30, y: screenHeight/2 - radius/2 + 30 , width: radius-60, height: radius - 60), cornerRadius: radius/2 - 30)
  
  path.append(circlePath)
  path.usesEvenOddFillRule = true
  fillLayer.path = path.cgPath
  fillLayer.fillRule = kCAFillRuleEvenOdd
  fillLayer.fillColor = UIColor.black.cgColor
  fillLayer.opacity = 0.5
  view.layer.addSublayer(fillLayer)
  </code></pre>