title: Create RGB image from each channel
body: <p>I have 3 files, one with only a red channel, one with only a green channel, one with only a blue channel. Now i want to combine those 3 images to one, where every image is one color-channel in the finished image.</p>
  
  <p>How can i do this with cocoa? I have a solution that is working but is too slow:</p>
  
  <pre><code>NSBitmapImageRep *rRep = [[rImage representations] objectAtIndex: 0];
  NSBitmapImageRep *gRep = [[gImage representations] objectAtIndex: 0];
  NSBitmapImageRep *bRep = [[bImage representations] objectAtIndex: 0];
  NSBitmapImageRep *finalRep = [rRep copy];
  for (NSUInteger i = 0; i &lt; [rRep pixelsWide]; i++) {
      for (NSUInteger j = 0; j &lt; [rRep pixelsHigh]; j++) {
          CGFloat r = [[rRep colorAtX:i y:j] redComponent];
          CGFloat g = [[gRep colorAtX:i y:j] greenComponent];
          CGFloat b = [[bRep colorAtX:i y:j] blueComponent];
          [finalRep setColor:[NSColor colorWithCalibratedRed:r green:g blue:b alpha:1.0] atX:i y:j];
      }
  }
  NSData *data = [finalRep representationUsingType:NSJPEGFileType properties:[NSDictionary dictionaryWithObject:[NSNumber numberWithDouble:0.7] forKey:NSImageCompressionFactor]];
  [data writeToURL:[panel URL] atomically:YES];
  </code></pre>