title: Preventing antialiasing from CALayer renderInContext
body: <p>I have a very simple <code>UIView</code> containing a few black and white <code>UIImageView</code>s.   If I take a screenshot via the physical buttons on the device, the resulting image looks exactly like what I see (as expected) - if I examine the image at the pixel level it is only black and white.   </p>
  
  <p>However, if I use the following snippet of code to perform the same action programmatically, the resulting image has what appears to be anti-aliasing applied - all the black pixels are surrounded by faint grey halos.   There is no grey in my original scene - it's pure black and white and the dimensions of the "screenshot" image is the same as the one I am generating programmatically, but I can not seem to figure out where the grey haloing is coming from.</p>
  
  <pre><code>UIView *printView = fullView;
  
  UIGraphicsBeginImageContextWithOptions(printView.bounds.size, NO, 0.0);
  
  CGContextRef ctx = UIGraphicsGetCurrentContext();
  [printView.layer renderInContext:ctx];
  UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
  UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
  UIGraphicsEndImageContext();
  </code></pre>
  
  <p>I've tried adding the following before the call to <code>renderInContext</code> in an attempt to prevent the antialiasing, but it has no noticeable effect:</p>
  
  <pre><code>CGContextSetShouldAntialias(ctx, NO);
  CGContextSetAllowsAntialiasing(ctx, NO);
  CGContextSetInterpolationQuality(ctx, kCGInterpolationHigh);
  </code></pre>
  
  <p>Here is a sample of the two different outputs - the left side is what my code produces and the right side is a normal iOS screenshot:</p>
  
  <p><img src="https://i.stack.imgur.com/dUTuu.png" alt="enter image description here"></p>
  
  <p>Since I am trying to send the output of my <code>renderInContext</code> to a monochrome printer, having grey pixels causes some ugly artifacting due to the printer's dithering algorithm.   </p>
  
  <p>So, how can I get <code>renderInContext</code> to produce the same pixel-level output of my views as a real device screenshot - i.e. just black and white as is what is in my original scene?</p>