title: Why do I get the wrong color of a pixel with following code?
body: <p>I create an UIImage with backgroundcolor <strong>RED</strong>:</p>
  
  <pre><code>let theimage:UIImage=imageWithColor(UIColor(red: 1, green: 0, blue: 0, alpha: 1) );
  
  func imageWithColor(color: UIColor) -&gt; UIImage {
      let rect = CGRectMake(0.0, 0.0, 200.0, 200.0)
      UIGraphicsBeginImageContext(rect.size)
      let context = UIGraphicsGetCurrentContext()
  
      CGContextSetFillColorWithColor(context, color.CGColor)
      CGContextFillRect(context, rect)
  
      let image = UIGraphicsGetImageFromCurrentImageContext()
      UIGraphicsEndImageContext()
  
      return image
  }
  </code></pre>
  
  <p>I am retrieving the color in the middle of the image as follow:</p>
  
  <pre><code>let h:CGFloat=theimage.size.height;
  let w:CGFloat=theimage.size.width;
  
  
  let test:UIColor=theimage.getPixelColor(CGPoint(x: 100, y: 100))
  
  var rvalue:CGFloat = 0;
  var gvalue:CGFloat = 0;
  var bvalue:CGFloat = 0;
  var alfaval:CGFloat = 0;
  test.getRed(&amp;rvalue, green: &amp;gvalue, blue: &amp;bvalue, alpha: &amp;alfaval);
  
  
  print("Blue Value : " + String(bvalue));
  print("Red Value : " + String(rvalue));
  
  
  extension UIImage {
      func getPixelColor(pos: CGPoint) -&gt; UIColor {
  
          let pixelData = CGDataProviderCopyData(CGImageGetDataProvider(self.CGImage))
          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>As result I get :</p>
  
  <p>Blue Value : 1.0
  Red Value : 0.0</p>
  
  <p>Why this ? I couldn't find the mistake.</p>