title: Use CGColorSpaceCreateDeviceGray but enable alpha
body: <p>I have an UIImage with some alpha values and want to make a gray version of it. I've been using the below, and it works for nonalpha parts of the image, however as alpha is not supported/turned off the alpha parts turn out black... How would I successfully turn alpha support on?</p>
  
  <p>(I modified this from code floating around stackoverflow, to support other scales (read retina))</p>
  
  <pre><code>-(UIImage*)grayscaledVersion2 {
      // Create image rectangle with current image width/height
      const CGRect RECT = CGRectMake(0, 0, self.size.width * self.scale, self.size.height * self.scale);
  
      // Grayscale color space
      CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();
  
      // Create bitmap content with current image size and grayscale colorspace
      CGContextRef context = CGBitmapContextCreate(nil, RECT.size.width, RECT.size.height, 8, 0, colorSpace, kCGImageAlphaNone);
      // kCGImageAlphaNone = no alpha, kCGImageAlphaPremultipliedFirst/kCGImageAlphaFirst/kCGImageAlphaLast = crash
  
      // Draw image into current context, with specified rectangle
      // using previously defined context (with grayscale colorspace)
      CGContextDrawImage(context, RECT, [self CGImage]);
  
      // Create bitmap image info from pixel data in current context
      CGImageRef imageRef = CGBitmapContextCreateImage(context);
  
      UIImage* imageGray = [UIImage imageWithCGImage:imageRef scale:self.scale orientation:self.imageOrientation];
      DLog(@"greyed %@ (%f, %f %f) into %@ (%f, %f %f)", self, self.scale, self.size.width, self.size.height, imageGray, imageGray.scale, imageGray.size.width, imageGray.size.height);
  
      // Release colorspace, context and bitmap information
      CGColorSpaceRelease(colorSpace);
      CGContextRelease(context);
      CFRelease(imageRef);
  
      return imageGray;
  }
  </code></pre>