title: How to create 8-, 4-, and 1-bit representations of NSImage
body: <p>I had created 32 bit NSImage with following code.</p>
  
  <pre><code> NSBitmapImageRep *sourceRep = [[NSBitmapImageRep alloc] initWithData: imageData];
  
          // create a new bitmap representation scaled down
  
              NSBitmapImageRep *newRep = 
                  [[NSBitmapImageRep alloc] 
                      initWithBitmapDataPlanes: NULL
                      pixelsWide: imageSize
                      pixelsHigh: imageSize
                      bitsPerSample: 8
                      samplesPerPixel: 4
                      hasAlpha: YES
                      isPlanar: NO
                      colorSpaceName: NSCalibratedRGBColorSpace
                      bytesPerRow: 0
                      bitsPerPixel: 0];
  
              // save the graphics context, create a bitmap context and set it as current
              [NSGraphicsContext saveGraphicsState] ;
              NSGraphicsContext *context = [NSGraphicsContext graphicsContextWithBitmapImageRep: newRep];
              [NSGraphicsContext setCurrentContext: context] ;
  
              // draw the bitmap image representation in it and restore the context
              [sourceRep drawInRect: NSMakeRect(0.0f, 0.0f, imageSize, imageSize)] ;
              [NSGraphicsContext restoreGraphicsState] ;
  
              // set the size of the new bitmap representation
              [newRep setSize: NSMakeSize(imageSize,imageSize)] ;
  
              NSDictionary *imageProps2 = [NSDictionary dictionaryWithObjectsAndKeys:
                                           [NSNumber numberWithFloat:1.0], kCGImageDestinationLossyCompressionQuality,
                                           nil];
              imageData = [newRep representationUsingType: NSPNGFileType properties: imageProps2];
    NSImage *bitImage  = [[NSImage alloc]initWithData:imageData];
  </code></pre>
  
  <p>Now I need to create 8 bit(256 Colors),4 bit(16 Colors),1 bit(Black &amp; White) <code>NSBitmapImageRep</code> representation. what I want to do now?</p>