title: iOS: 2 Step Image Processing with CoreGraphics
body: <p>Using CoreGraphics (inside my drawRect method), I'm trying to apply a blend mode to an image (transparent png), and then adjust the alpha of the result. I'm assuming that this needs to be done in two steps, but I could be wrong. Here's what I have so far (which works fine):</p>
  
  <pre><code>CGContextRef context = UIGraphicsGetCurrentContext();
  
  CGContextSaveGState(context);
  
  //SET COLOR - EDIT... added a more practical color example
  CGContextSetRGBFillColor(context, 0.0, 1.0, 0.0, 1);
  
  //flips drawing context (apparently this is necessary)
  CGContextTranslateCTM(context, 0.0, self.bounds.size.height);
  CGContextScaleCTM(context, 1.0, -1.0);//flip context
  
  //DRAW PIN IMAGE
  UIImage *pin = [UIImage imageNamed:@"pin"];
  CGRect pinrect = CGRectMake(12, 17, 25, 25);    
  CGContextDrawImage(context, pinrect, pin.CGImage);//draws image in context
  
  //Apply blend mode
  CGContextSetBlendMode(context, kCGBlendModeColor); 
  CGContextClipToMask(context, pinrect, pin.CGImage); // restricts drawing to within alpha channel
  
  //fills context with mask, applying blend mode
  CGContextFillRect(context, pinrect); 
  
  CGContextRestoreGState(context);
  
  // -- Do something here to make result 50% transparent ?? --
  </code></pre>
  
  <p>I'm assuming that I need to draw all this into some kind of separate context somewhere, call  <code>CGContextSetAlpha(...)</code>, and then re-draw it back to my original context, but I'm not sure how.  Setting the alpha before my final CGContextFillRect will just change the amount that the blend mode was applied, not the alpha of the entire image.</p>
  
  <p>EDIT: screenshot posted</p>
  
  <p><img src="https://i.stack.imgur.com/IyqR9.jpg" alt="enter image description here"></p>
  
  <p>Thanks in advance.</p>