title: How do I get the RGB Value of a pixel using CGContext?
body: <p>I'm trying to edit images by changing the pixels.</p>
  
  <p>I have the following code:</p>
  
  <pre><code>    let imageRect = CGRectMake(0, 0, self.image.image!.size.width, self.image.image!.size.height)
  
      UIGraphicsBeginImageContext(self.image.image!.size)
      let context = UIGraphicsGetCurrentContext()
  
      CGContextSaveGState(context)
      CGContextDrawImage(context, imageRect, self.image.image!.CGImage)
  
      for x in 0...Int(self.image.image!.size.width) {
          for y in 0...Int(self.image.image!.size.height) {
              var red = 0
              if y % 2 == 0 {
                  red = 255
              }
  
              CGContextSetRGBFillColor(context, CGFloat(red/255), 0.5, 0.5, 1)
              CGContextFillRect(context, CGRectMake(CGFloat(x), CGFloat(y), 1, 1))
          }
      }
      CGContextRestoreGState(context)
      self.image.image = UIGraphicsGetImageFromCurrentImageContext()
  </code></pre>
  
  <p>I'm looping through all the pixels and changing the value of the each pixel, then converting it back to an image. Want I want to do is somehow get the value of the current pixel (in the y-for-loop) and do something with that data. I have not found anything on the internet about this particular problem.</p>