iOS UIImageView 缩小图像在 iPad 2 上产生锯齿图像 [英] iOS UIImageView scaling image down produces aliased image on iPad 2

查看:23
本文介绍了iOS UIImageView 缩小图像在 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.

图像通常从大约 500 像素 x 500 像素缩小到 100 像素 x 100 像素.在 Retina 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.

示例:

原始图片

100px x 100px 的 Retina iPad 渲染

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆