title: How to save PNG file from NSImage (retina issues)
body: <p>I'm doing some operations on images and after I'm done, I want to save the image as PNG on disk. I'm doing the following:</p>
  
  <pre><code>+ (void)saveImage:(NSImage *)image atPath:(NSString *)path {
  
      [image lockFocus] ;
      NSBitmapImageRep *imageRepresentation = [[NSBitmapImageRep alloc] initWithFocusedViewRect:NSMakeRect(0.0, 0.0, image.size.width, image.size.height)] ;
      [image unlockFocus] ;
  
      NSData *data = [imageRepresentation representationUsingType:NSPNGFileType properties:nil];
      [data writeToFile:path atomically:YES];
  }
  </code></pre>
  
  <p>This code is working, but the problem is with retina mac, if I print the NSBitmapImageRep object I get a different size and pixels rect and when my image is saved on disk, it's twice the size:</p>
  
  <pre><code>$0 = 0x0000000100413890 NSBitmapImageRep 0x100413890 Size={300, 300} ColorSpace=sRGB IEC61966-2.1 colorspace BPS=8 BPP=32 Pixels=600x600 Alpha=YES Planar=NO Format=0 CurrentBacking=&lt;CGImageRef: 0x100414830&gt;
  </code></pre>
  
  <p>I tied to force the pixel size to not take care about the retina scale, as I want to preserve the original size:</p>
  
  <pre><code>imageRepresentation.pixelsWide = image.size.width;
  imageRepresentation.pixelsHigh = image.size.height;
  </code></pre>
  
  <p>This time I get the right size when I print the NSBitmapImageRep object, but when I save my file I still get the same issue:</p>
  
  <pre><code>$0 = 0x0000000100413890 NSBitmapImageRep 0x100413890 Size={300, 300} ColorSpace=sRGB IEC61966-2.1 colorspace BPS=8 BPP=32 Pixels=300x300 Alpha=YES Planar=NO Format=0 CurrentBacking=&lt;CGImageRef: 0x100414830&gt;
  </code></pre>
  
  <p>Any idea how to fix this, and preserve the original pixel size?</p>