I think the documentation is correct (pixels are pixels) based on this test:
var filename = "InterfaceButtons_Scores@2x.png"
var path = NSBundle.mainBundle().pathForResource(filename,ofType:nil)
var dataProvider = CGDataProviderCreateWithFilename(path!)
var cgimg = CGImageCreateWithPNGDataProvider(dataProvider, nil, false, .RenderingIntentDefault)!
print("size of 100x100px file loaded into CGImage")
print(CGImageGetHeight(cgimg));
print(CGImageGetWidth(cgimg));
var croppedImg = CGImageCreateWithImageInRect(cgimg, CGRect(x: 0, y: 0, width: 100, height: 100))
print("size of CGImage created with 100x100 Rect from 100x100 image")
print(CGImageGetHeight(croppedImg));
print(CGImageGetWidth(croppedImg));
filename = "InterfaceButtons_Scores@1x.png"
path = NSBundle.mainBundle().pathForResource(filename,ofType:nil)
dataProvider = CGDataProviderCreateWithFilename(path!)
cgimg = CGImageCreateWithPNGDataProvider(dataProvider, nil, false, .RenderingIntentDefault)!
print("size of 51x51px file loaded into CGImage")
print(CGImageGetHeight(cgimg));
print(CGImageGetWidth(cgimg));
croppedImg = CGImageCreateWithImageInRect(cgimg, CGRect(x: 0, y: 0, width: 100, height: 100))
print("size of CGImage created with 100x100 Rect from 51x51 image")
print(CGImageGetHeight(croppedImg));
print(CGImageGetWidth(croppedImg));
output:
size of 100x100px file loaded into CGImage
100
100
size of CGImage created with 100x100 Rect from 100x100 image
100
100
size of 51x51px file loaded into CGImage
51
51
size of CGImage created with 100x100 Rect from 51x51 image
51
51
I'm not sure what to say about your UIImage resizing without knowing exactly how you're trying to resize them and the exact results you saw. I do know that if you created the UIImage from an asset in an asset catalog (using UIImage(named:)), the actual pixel dimensions of the CGImage property will depend on the scale factor of the device or simulator. If there are multiple sizes for the same asset, the UIImage will load whichever asset matches the system's scale factor. In other words, in this scenario, you can't count on the UIImage's CGImage having consistent dimensions, and scaling code may go awry.