title: transparency/alpha in CoreGraphics context (iphone, objc)
body: <p>I am currently making a basic image editor for iphone.</p>
  
  <p>I take the <code>CGImageRef</code> from a <code>UIImage</code> and create a context for it using the following code</p>
  
  <pre><code>origImage = result.CGImage;
  
  Iheight = CGImageGetHeight(origImage);
  Iwidth = CGImageGetWidth(origImage);
  IcolorSpace = CGColorSpaceCreateDeviceRGB();
  IrawData = malloc(Iheight * Iwidth * 4);
  IbytesPerPixel = 4;
  IbytesPerRow = IbytesPerPixel * Iwidth;
  IbitsPerComponent = 8;
  Icontext = CGBitmapContextCreate(IrawData, Iwidth, Iheight, IbitsPerComponent,
                                   IbytesPerRow, IcolorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big
                                   );
  //[bytesPerRow release];
  CGContextSetBlendMode(Icontext, kCGBlendModeCopy);
  CGContextDrawImage(Icontext, CGRectMake(0,0,Iwidth,Iheight),  origImage);
  </code></pre>
  
  <p>I then loop through the pixels</p>
  
  <pre><code>for (int x=0; x&lt;Iwidth; x++) {
      for (int y=0; y&lt;Iheight; y++) {
              //and  set the alpha component to 0
              int byteIndex = (y*IbytesPerRow) + x*IbytesPerPixel;
  
              IrawData[byteIndex+3] = 0;
  
              }
  }
  </code></pre>
  
  <p>and then create a CGImageRef from the context with </p>
  
  <pre><code>    CGImageRef imagea = CGBitmapContextCreateImage(Icontext);
  </code></pre>
  
  <p>and add the CGImage to a UIImage and assign to a UIImageView</p>
  
  <p><strong>The problem  is that the change of alpha isn't effecting the resultant image</strong></p>
  
  <p>if I change the colour of the pixels with</p>
  
  <pre><code>IrawData[byteIndex+(0/1/2)]
  </code></pre>
  
  <p>the colour changes, but <strong>I still can't change the alpha of the pixel</strong></p>
  
  <p>Thank you,</p>
  
  <p>nonono</p>