title: Extracting RGB data from bitmapData (NSBitmapImageRep) Cocoa
body: <p>I am working on an application which needs to compare two images, in order to see how different they are and the application does this repeatedly for different images. So the way I currently do this is by having both the images as <code>NSBitmapImageRep</code>, then using the <code>colorAtX: y:</code> function in order to get a <code>NSColor</code> object, and then examining the RGB components. But this approach is extremely slow. So researching around the internet I found posts saying that a better way would be to get the bitmap data, using the function bitmapData, which returns an unsigned char. Unfortunately for me I don't know how to progress further from here, and none of the posts I've found show you how to actually get the RGB components for each pixel from this <code>bitmapData</code>. So currently I have :</p>
  
  <pre><code> NSBitmapImageRep* imageRep = [self screenShot]; //Takes a screenshot of the content displayed in the nswindow
  unsigned char *data = [imageRep bitmapData]; //Get the bitmap data
  
  //What do I do here in order to get the RGB components?
  </code></pre>
  
  <p>Thanks</p>