在iOS Swift中,可以使用以下方法来正确缩小图像的比例:
let scaledImage = originalImage.scale(to: CGSize(width: originalImage.size.width/2, height: originalImage.size.height/2))
func scaleImage(image: UIImage, scale: CGFloat) -> UIImage? {
let size = CGSize(width: image.size.width * scale, height: image.size.height * scale)
UIGraphicsBeginImageContextWithOptions(size, false, 0.0)
image.draw(in: CGRect(origin: .zero, size: size))
let scaledImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return scaledImage
}
let scaledImage = scaleImage(image: originalImage, scale: 0.5)
缩小图像的比例可以在以下场景中使用:
腾讯云相关产品和产品介绍链接地址:
领取专属 10元无门槛券
手把手带您无忧上云