title: How to create a CGBitmapContext which works for Retina display and not wasting space for regular display?
body: <p>Is it true that if it is in UIKit, including <code>drawRect</code>, the HD aspect of Retina display is automatically handled?  So does that mean in <code>drawRect</code>, the current graphics context for a 1024 x 768 view is actually a 2048 x 1536 pixel Bitmap context? </p>
  
  <p>(<strong>Update:</strong> if I create an image using the current context in <code>drawRect</code> and print its size:</p>
  
  <pre><code>CGContextRef context = UIGraphicsGetCurrentContext();
  CGImageRef image = CGBitmapContextCreateImage(context);
  NSLog(@"width of context %i", (int) CGImageGetWidth(image));
  NSLog(@"height of context %i", (int) CGImageGetHeight(image));
  </code></pre>
  
  <p>then on the new iPad, with the status bar disabled, 2048 and 1536 is printed, and iPad 2 will show 1024 and 768)</p>
  
  <p>We actually enjoy the luxury of 1 point = 4 pixels automatically handled for us.</p>
  
  <p>However, if we use <code>CGBitmapContextCreate</code>, then those will really be pixels, not points?  (at least if we provide a data buffer for that bitmap, the size of the buffer (number of bytes) is obviously not for higher resolution, but for standard resolution, and even if we pass <code>NULL</code> as the buffer so that <code>CGBitmapContextCreate</code> handles the buffer for us, the size probably is the same as if we pass in a data buffer, and it is just standard resolution, not Retina's resolution).</p>
  
  <p>We can always create 2048 x 1536 for iPad 1 and iPad 2 as well as the New iPad, but it will waste memory and processor and GPU power, as it is only needed for the New iPad.</p>
  
  <p>So do we have to use a <code>if () { } else { }</code> to create such a bitmap context and how do we actually do so?  And all our code <code>CGContextMoveToPoint</code> has to be adjusted for Retina display to use <code>x * 2</code> and <code>y * 2</code> vs non-retina display of just using <code>x, y</code> as well?  That can be quite messy for the code.  (or maybe we can define a local variable <code>scaleFactor</code> and set it to <code>[[UIScreen mainScreen] scale]</code> so it is 1 for standard resolution and 2 if it is retina, so our <code>x</code> and <code>y</code> will always be <code>x * scaleFactor</code>, <code>y * scaleFactor</code> instead of just <code>x</code> and <code>y</code> when we draw using <code>CGContextMoveToPoint</code>, etc.)</p>
  
  <p>It seems that <code>UIGraphicsBeginImageContextWithOptions</code> can create one for Retina automatically if the scale of 0.0 is passed in, but I don't think it can be used if I need to create the context and keep it (and using ivar or property of UIViewController to hold it).  If I don't release it using <code>UIGraphicsEndImageContext</code>, then it stays in the graphics context stack, so it seems like I have to use <code>CGBitmapContextCreate</code> instead.  (or do we just let it stay at the bottom of the stack and not worry about it?)</p>