2016-02-03 86 views
3

如果我只是将image.size与image.scale相乘,可以获取UIImage的像素大小吗?是否这样做:以像素为单位的UIImage大小

guard let cgImage = image.CGImage else{ 
     return nil 
    } 
    let width = CGImageGetWidth(cgImage) 
    let height = CGImageGetHeight(cgImage) 

回答

6

是的。

CGImageGetWidthCGImageGetHeight将返回与image.size * image.scale返回相同的大小(以像素为单位)。

0

你可以,但它是不一样的作为cgImage.width x cgImage.height(您提供的CG函数的新名称)。 cgImage至少不知道可能旋转或翻转原始图像的某些EXIF标志。您可以通过Portrait_8.jpg在https://github.com/recurser/exif-orientation-examples处看到图像Portrait_5.jpg与图像的区别。 image.size.height * image.scale给出1800,但cgImage.height给出1200(真正的宽度)。

相关问题