title: Hot can I add a shadow to an image using CoreGraphics on the iPhone?
body: <p>I have a problem concerning Core Graphics drawing a shadow under my masked image.</p>
  
  <p>I wrote a method to turn a grey image (actually it's an icon) into a white using a mask. Now I want to draw a shadow underneath it.</p>
  
  <p>That's my code so far:</p>
  
  <p>
  
  <pre><code>CGContextRef context = CGBitmapContextCreate(NULL, imageRect.size.width, imageRect.size.height, 8, 0, CGImageGetColorSpace(image.CGImage), kCGImageAlphaPremultipliedLast);
  
  CGContextSetRGBFillColor(context, 1, 1, 1, 1);
  CGContextFillRect(context, imageRect);
  
  CGContextClipToMask(context, imageRect, image.CGImage);
  
  CGContextSetRGBFillColor(context, 0, 0, 0, 1);
  CGContextFillRect(context, imageRect);
  
  CGImageRef bwCGImage = CGBitmapContextCreateImage(context);
  UIImage *bwImage = [UIImage imageWithCGImage:bwCGImage scale:image.scale orientation:image.imageOrientation];
  
  CGContextRelease(context);
  CGImageRelease(bwCGImage);
  
  
  UIGraphicsBeginImageContextWithOptions(image.size, NO, 0.0);
  [[UIColor whiteColor] set];
  UIRectFill(CGRectMake(0, 0, image.size.width, image.size.height));
  
  UIImage *normalBackgroundImage = UIGraphicsGetImageFromCurrentImageContext();
  UIGraphicsEndImageContext();
  
  
  CGImageRef imageMask = CGImageMaskCreate(CGImageGetWidth(bwImage.CGImage), CGImageGetHeight(bwImage.CGImage), CGImageGetBitsPerComponent(bwImage.CGImage), CGImageGetBitsPerPixel(bwImage.CGImage), CGImageGetBytesPerRow(bwImage.CGImage), CGImageGetDataProvider(bwImage.CGImage), NULL, YES);
  
  CGImageRef normalImageRef = CGImageCreateWithMask(normalBackgroundImage.CGImage, imageMask);
  
  UIImage *normalImage = [UIImage imageWithCGImage:normalImageRef scale:image.scale orientation:image.imageOrientation];
  
  
  CGImageRelease(imageMask);
  CGImageRelease(normalImageRef);
  </code></pre>
  
  <p>Actually everything is working fine. Only the shadow is missing. How can I draw it?</p>