2016-02-03 84 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(真正的寬度)。

相關問題