在iOS中,如何在放大位图时保留锐边?

当您将UIImage放入比视图小的UIImageView ,并且视图的内容模式是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; 

我希望我的回答对你有用。