title: How to load JPG file into NSBitmapImageRep?
body: <p>Objective-C / Cocoa:
  I need to load the image from a JPG file into a two dimensional array so that I can access each pixel.  I am trying (unsuccessfully) to load the image into a NSBitmapImageRep.  I have tried several variations on the following two lines of code:</p>
  
  <pre><code>NSString *filePath = [NSString stringWithFormat: @"%@%@",@"/Users/adam/Documents/phoneimages/", [outLabel stringValue]];  //this coming from a window control
  NSImageRep *controlBitmap = [[NSImageRep alloc] imageRepWithContentsOfFile:filePath];
  </code></pre>
  
  <p>With the code shown, I get a runtime error: -[NSImageRep imageRepWithContentsOfFile:]: unrecognized selector sent to instance 0x100147070.  </p>
  
  <p>I have tried replacing the second line of code with: </p>
  
  <pre><code>NSImage *controlImage = [[NSImage alloc] initWithContentsOfFile:filePath];
  NSBitmapImageRep *controlBitmap = [[NSBitmapImageRep alloc] initWithData:controlImage];
  </code></pre>
  
  <p>But this yields a compiler error 'incompatible type' saying that initWithData wants a NSData variable not an NSImage.</p>
  
  <p>I have also tried various other ways to get this done, but all are unsuccessful either due to compiler or runtime error.  Can someone help me with this?  I will eventually need to load some PNG files in the same way (so it would be nice to have a consistent technique for both).</p>
  
  <p>And if you know of an easier / simpler way to accomplish what I am trying to do (i.e., get the images into a two-dimensional array), rather than using NSBitmapImageRep, then please let me know!  And by the way, I know the path is valid (confirmed with fileExistsAtPath) -- and the filename in outLabel is a file with .jpg extension.</p>
  
  <p>Thanks for any help!</p>