title: cocoa render bitmap to file
body: <p>I would like to create a bitmap in memory, set some of the pixel values, then save that image to disk.</p>
  
  <p>So far I have the NSBitmapImageRep:</p>
  
  <pre><code>image = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
                                                  pixelsWide:width
                                              pixelsHigh:height
                                               bitsPerSample:8
                                             samplesPerPixel:4
                                                    hasAlpha:YES
                                                    isPlanar:NO
                                              colorSpaceName:NSDeviceRGBColorSpace
                                                 bytesPerRow:0
                                                bitsPerPixel:0];
  </code></pre>
  
  <p>Then simply add some pixels like so:</p>
  
  <pre><code>NSColor *color = [NSColor colorWithDeviceRed:1.0
                                         green:1.0
                                          blue:1.0
                                         alpha:1.0];
  
  
  [image setColor:color
              atX:x
                y:y];
  </code></pre>
  
  <p>And eventually save the image (as a tiff, which is not ideal but a good start)</p>
  
  <pre><code>NSData* TIFFData = [image TIFFRepresentation];
  [TIFFData writeToFile:@"/temp/image.tiff" atomically:YES];
  </code></pre>
  
  <p>The image saved from this code is actually empty and only shows a few pixels in the top left corner. I'm not sure where the wheels are coming off, but it seems obvious that I am going out this the wrong way?</p>