iOS UIImageView按比例缩小图像会在iPad 2上生成别名图像 [英] iOS UIImageView scaling image down produces aliased image on iPad 2
问题描述
我正在使用UIImageView显示图像的缩略图,然后可以选择以全尺寸查看。 UIImageView的内容模式设置为宽高比适合。
I am using UIImageView to display thumbnails of images that can then be selected to be viewed at full size. The UIImageView has its content mode set to aspect fit.
图像通常从大约500px x 500px缩小到100px x 100px。在视网膜iPad上,它们显示得非常好,而在iPad2上,它们的颜色非常混乱,直到尺寸接近原始图像尺寸。
The images are usually scaled down from around 500px x 500px to 100px x 100px. On the retina iPad they display really well while on the iPad2 they are badly aliased until the size gets closer to the native image size.
示例:
原始图像
Retina iPad渲染为100px x 100px
Retina iPad rendering at 100px x 100px
iPad 2渲染速度为100px x 100px
iPad 2 rendering at 100px x 100px
iPad 2和新iPad之间的区别可能只是屏幕分辨率,或者可能是GPU更适合缩放图像。无论哪种方式,iPad 2渲染都非常差。
The difference between iPad 2 and new iPad might just be the screen resolution or could be that the GPU is better equipped to scale images. Either way, the iPad 2 rendering is very poor.
我首先尝试通过创建新的上下文来减小图像大小,将插值质量设置为高并绘制图像进入上下文。在这种情况下,两张iPad上的图像看起来都很好。
I have tried first reducing the image size by creating a new context, setting the interpolation quality to high and drawing the image into the context. In this case, the image looks fine on both iPads.
在我继续图像复制/调整大道之前,我想检查一下我没有更简单的东西失踪。我很欣赏UIImage不是可以扩展的,但我的印象是UIImageView可以处理扩展,但目前它似乎没有做好缩小的工作。我错过了什么(如果有的话)?
Before I continue down the image copy/resize avenue, I wanted to check there wasn't something simpler I was missing. I appreciate that UIImage isn't there to be scaled but I was under the impression UIImageView was there to handle scaling but at the moment it doesn't seem to be doing a good job scaling down. What (if anything) am I missing?
更新:注意:渲染/调整大小的图像上的阴影会添加到代码中。禁用此功能对缩放的质量没有任何影响。
Update: Note: The drop shadow on the rendered / resized images is added in code. Disabling this made no difference to the quality of the scaling.
推荐答案
我试过的另一种方法似乎确实在改进是设置minificationFilter:
Another approach I've tried that does seem to be improving things is to set the minificationFilter:
[imageView.layer setMinificationFilter:kCAFilterTrilinear]
质量肯定有所改善,我没有发现性能受到影响。
The quality is certainly improved and I haven't noticed a performance hit.
这篇关于iOS UIImageView按比例缩小图像会在iPad 2上生成别名图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!