ios - 在 iOS 中,如何在放大位图时保留锐利的边缘?

标签 ios uiimageview uiimage

当你把 UIImage变成 UIImageView小于 View , View 的内容模式为ScaleToFit , iOS 按预期放大位图。我从未预料到的是它会模糊它放大的像素的边缘。如果您正在看照片,我可以看到这可能是一个不错的选择,但在许多其他情况下,我希望看到那些讨厌的、坚硬的、笔直的边缘!

有谁知道如何配置 UIImageUIImageView用锐利的像素边缘放大?那就是:让它看起来像素化,而不是模糊。

谢谢!

最佳答案

如果你想放大 UIImageView 中的任何图像并锐化边缘,请使用 CALayer 的以下属性.

imageview.layer.magnificationFilter = kCAFilterNearest;

看来magnificationFilter影响 UIView 内容的插值方法。我建议您阅读 CALayer.h 中对该属性的说明。
/* The filter types to use when rendering the `contents' property of
 * the layer. The minification filter is used when to reduce the size
 * of image data, the magnification filter to increase the size of
 * image data. Currently the allowed values are `nearest' and `linear'.
 * Both properties default to `linear'. */

@property(copy) NSString *minificationFilter, *magnificationFilter;

希望我的回答对你有用。

关于ios - 在 iOS 中,如何在放大位图时保留锐利的边缘?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22853863/

相关文章:

ios - iTunes Connect-App Store区域

ios - 如何以编程方式为 en 和 ar 语言环境布局带有文本的 UIImageView?

ios - Autolayout UIImageView 具有不遵循约束的编程调整大小

ios - 如何调整物镜C中具有透明部分的图像的大小

ios - 将 CIGaussianBlur 应用于 UIImage 无法正常工作

ios - 如何拖放具有相同代码的任何对象?

ios - 尝试在 iOS 中动态调整 UITableView 的大小时出现运行时异常

ios - 使用通过点击 API 获得的响应进行填充时, Collection View 会卡住很长时间

iphone - UIImageView 在 CAKeyframeAnimation 之后消失

ios - 调整大小并放置来自服务器的 Retina UIImage