我正在使用此方法来调整图像大小:
func imageToResizedImage(image: UIImage, size: CGSize) -> UIImage {
UIGraphicsBeginImageContext(size)
image.drawInRect(CGRectMake(0,0, size.width, size.height))
let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return newImage
}
但是,当我将其尺寸缩小(例如缩小 50%)时,我发现分辨率变得更差。它变得模糊。
我可以在代码中添加什么以使分辨率仍然清晰?
最佳答案
UIGraphicsBeginImageContext
创建比例因子为 1.0 的上下文,这与任何现代 iOS 设备的屏幕分辨率(2.0 或 3.0)不匹配。来自 documentation :
This function is equivalent to calling the UIGraphicsBeginImageContextWithOptions function with the opaque parameter set to NO and a scale factor of 1.0.
使用UIGraphicsBeginImageContextWithOptions
代替;如果您向其传递比例因子 0.0,它将默认为设备主屏幕的比例。
关于ios - 调整图像大小会降低分辨率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38385338/