title: How do I apply multiple color masks using CGImageCreateWithMaskingColors?
body: <p>I'm a bit new to objective-c and even newer at programming with Quartz 2D, so apologies in advance!  I've got a method where I would like to remove a handful of specific colors (not just one) from a UIImage.</p>
  
  <p>When I run my project with just one color mask being applied, it works beautifully.  Once I try stacking them, the 'whiteRef' comes out NULL.  I've even tried modifying my method to take a color mask and then simply ran my method twice -feeding in the different colors masks- but still no go.</p>
  
  <p>Any help with this is greatly appreciated!</p>
  
  <pre><code>- (UIImage *)doctorTheImage:(UIImage *)originalImage
  {
      const float brownsMask[6] = {124, 255, 68, 222, 0, 165};
      const float whiteMask[6] = {255, 255,  255, 255, 255, 255};
  
      UIImageView *imageView = [[UIImageView alloc] initWithImage:originalImage];
  
      UIGraphicsBeginImageContext(originalImage.size);
      CGContextRef context = UIGraphicsGetCurrentContext();
  
      CGImageRef brownRef = CGImageCreateWithMaskingColors(imageView.image.CGImage, brownsMask);    
      CGImageRef whiteRef = CGImageCreateWithMaskingColors(brownRef, whiteMask);    
      CGContextDrawImage (context, CGRectMake(0, 0, imageView.image.size.width, imageView.image.size.height), whiteRef);
  
      CGImageRelease(brownRef);
      CGImageRelease(whiteRef);
  
      UIImage *doctoredImage = UIGraphicsGetImageFromCurrentImageContext();
      UIGraphicsEndImageContext();
      [imageView release];
  
      return doctoredImage;
  }
  </code></pre>