如何为所有 iPhone 分辨率选择 1 个 UIImage 大小?
How to choose 1 UIImage size for all iPhone resolutions?
如果我(目前)只能添加一种图片尺寸,我应该选择什么尺寸的图片?
图片将在 UITableViewCell
中使用,很可能宽度是从边到边的,而高度可能会有所不同。
那么我应该添加 1242 像素宽度的图像,然后应用程序本身会将其缩小到 750/640 像素吗?或者我应该使用 750px,因为 iPhone 6 位用户多于 6 位以上用户,更多用户会看到更好看的图像(换句话说,更多人会看到原始图像,而不是缩放后的图像)?
使用 1242px 图像并缩小它。要获得最佳图像质量集 yourUIImageView.layer.minificationFilter = kCAFilterTrilinear
。使用三线性过滤时,您不会看到图像质量有任何差异。
另一个选项是在使用之前缩小图像:
extension UIImage {
public func rescale(width: CGFloat, _ height: CGFloat) -> UIImage {
let newSize = CGSizeMake(width, height)
UIGraphicsBeginImageContextWithOptions(newSize, false, 0.0)
drawInRect(CGRectMake(0.0, 0.0, newSize.width, newSize.height))
let scaledImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return scaledImage
}
}
let myImage = UIImage(named: "myimage").rescale(newWidth, newHeight)
如果我(目前)只能添加一种图片尺寸,我应该选择什么尺寸的图片?
图片将在 UITableViewCell
中使用,很可能宽度是从边到边的,而高度可能会有所不同。
那么我应该添加 1242 像素宽度的图像,然后应用程序本身会将其缩小到 750/640 像素吗?或者我应该使用 750px,因为 iPhone 6 位用户多于 6 位以上用户,更多用户会看到更好看的图像(换句话说,更多人会看到原始图像,而不是缩放后的图像)?
使用 1242px 图像并缩小它。要获得最佳图像质量集 yourUIImageView.layer.minificationFilter = kCAFilterTrilinear
。使用三线性过滤时,您不会看到图像质量有任何差异。
另一个选项是在使用之前缩小图像:
extension UIImage {
public func rescale(width: CGFloat, _ height: CGFloat) -> UIImage {
let newSize = CGSizeMake(width, height)
UIGraphicsBeginImageContextWithOptions(newSize, false, 0.0)
drawInRect(CGRectMake(0.0, 0.0, newSize.width, newSize.height))
let scaledImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return scaledImage
}
}
let myImage = UIImage(named: "myimage").rescale(newWidth, newHeight)