title: Getting pixelColour only one time
body: <p>Below function I call in a loop, it gives the correct answer for the first time only.
  it's not giving the correct pixel color after the first call of the function <code>getPixelColor(pos: CGPoint)</code>.</p>
  
  <pre><code>extension UIImage {
      func getPixelColor(pos: CGPoint) -&gt; UIColor {
  
          let pixelData = self.cgImage!.dataProvider!.data
          let data: UnsafePointer&lt;UInt8&gt; = CFDataGetBytePtr(pixelData)
  
          let pixelInfo: Int = ((Int(self.size.width) * Int(pos.y)) + Int(pos.x)) * 4
  
          let r = CGFloat(data[pixelInfo]) / CGFloat(255.0)
          let g = CGFloat(data[pixelInfo+1]) / CGFloat(255.0)
          let b = CGFloat(data[pixelInfo+2]) / CGFloat(255.0)
          let a = CGFloat(data[pixelInfo+3]) / CGFloat(255.0)
  
          return UIColor(red: r, green: g, blue: b, alpha: a)
      }
  
  }
  </code></pre>
  
  <p>Below code is used to color in the image in location, where we touch.</p>
  
  <pre><code>  UIGraphicsBeginImageContextWithOptions((rect?.size)!, false, (images?.scale)!)
          let c = UIGraphicsGetCurrentContext()
          images?.draw(in: rect!)
  
          c!.setFillColor(UIColor.red.cgColor)
          c!.setBlendMode(CGBlendMode.normal)
  
  
          c!.fill(CGRect(x: (location?.x)!, y: (location?.y)!, width: 10, height:10))
  
           let result = UIGraphicsGetImageFromCurrentImageContext()
          UIGraphicsEndImageContext()
  
          img.image = result
  </code></pre>
  
  <p>But, after coloring image first time, then above <code>getPixelColor(pos: CGPoint)</code> is not working.</p>
  
  <p>let me know if anyone has solution. </p>
  
  <pre><code>  UIGraphicsBeginImageContextWithOptions((rect?.size)!, false, (Images?.scale)!)
          let c = UIGraphicsGetCurrentContext()
          Images?.draw(in: rect!)
  
          c!.setFillColor(UIColor.red.cgColor)
          c!.setBlendMode(CGBlendMode.normal)
  
          while ((i) != 200) {
  </code></pre>
  
  <blockquote>
    <p>// here function calls in loop</p>
  </blockquote>
  
  <pre><code>            let colors = Images?.getPixelColor(pos: CGPoint(x:(location?.x)! + CGFloat(i!),y:(location?.y)!))
  
  
  
              print((location?.x)! + CGFloat(i!),(location?.y)!)
              let Red = colors?.cgColor.components?[0]
              let Green = colors?.cgColor.components?[1]
              let Blue = colors?.cgColor.components?[2]
              let Alpha = colors?.cgColor.components?[3]
              print(Red)
              print(Green)
              print(Blue)
              print(Alpha)
              if Red == 0 &amp;&amp; Green == 0 &amp;&amp; Blue == 0 {
                  c!.fill(CGRect(x: (location?.x)! + CGFloat(i!), y: ((location?.y)!), width: 1, height:1))
  //
  
  
             }
               i = i! - 1
          }
  
  
          let result = UIGraphicsGetImageFromCurrentImageContext()
          UIGraphicsEndImageContext()
  </code></pre>