title: Get alpha channel from UIImage rectangle
body: <p>Given a CGRect (<code>rect</code>) and a UIImage (<code>image</code>), how do you obtain the alpha values (only) of the image pixels in the rectangle?</p>
  
  <p>The following code always returns 0 alpha, no matter the image or rectangle.</p>
  
  <pre><code>CGContextRef context = CGBitmapContextCreate(NULL,
                                               rect.size.width,
                                               rect.size.height,
                                               8,
                                               rect.size.width,
                                               NULL,
                                               kCGImageAlphaOnly);
  
  UIGraphicsPushContext(context);
  [image drawInRect:rect];
  char *pixels = CGBitmapContextGetData(context);
  NSUInteger pixelCount = rect.size.width * rect.size.height;
  for (int i = 0; i &lt; pixelCount; i++)
  {
      char pixel = pixels[i];
      CGFloat alpha = pixel / 255.0;
      NSLog(@"%f", alpha);
  }
  UIGraphicsPopContext();
  CGContextRelease(context);
  </code></pre>