如果我只是将image.size与image.scale相乘,可以获取UIImage的像素大小吗?是否这样做:以像素为单位的UIImage大小
guard let cgImage = image.CGImage else{
return nil
}
let width = CGImageGetWidth(cgImage)
let height = CGImageGetHeight(cgImage)
如果我只是将image.size与image.scale相乘,可以获取UIImage的像素大小吗?是否这样做:以像素为单位的UIImage大小
guard let cgImage = image.CGImage else{
return nil
}
let width = CGImageGetWidth(cgImage)
let height = CGImageGetHeight(cgImage)
是的。
CGImageGetWidth
和CGImageGetHeight
将返回与image.size * image.scale
返回相同的大小(以像素为单位)。
你可以,但它是不一样的作为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(真正的宽度)。