当你把 UIImage
变成 UIImageView
小于 View , View 的内容模式为ScaleToFit
, iOS 按预期放大位图。我从未预料到的是它会模糊它放大的像素的边缘。如果您正在看照片,我可以看到这可能是一个不错的选择,但在许多其他情况下,我希望看到那些讨厌的、坚硬的、笔直的边缘!
有谁知道如何配置 UIImage
或 UIImageView
用锐利的像素边缘放大?那就是:让它看起来像素化,而不是模糊。
谢谢!
最佳答案
如果你想放大 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/