在iOS中,如何在放大位图时保留锐边? [英] In iOS, how do you preserve sharp edges when enlarging a bitmap?
问题描述
当您将 UIImage
放入小于视图的 UIImageView
时,以及内容模式view是 ScaleToFit
,iOS会按预期放大位图。我没想到的是它模糊了它放大的像素的边缘。我可以看到,如果你正在看照片,这可能是一个很好的接触,但在许多其他情况下,我想看到那些讨厌,坚硬,直的边缘!
When you put a UIImage
into a UIImageView
that is smaller than the view, and the content mode of the view is ScaleToFit
, iOS enlarges the bitmap, as expected. What I have never expected is that it blurs the edges of the pixels it has scaled-up. I can see this might be a nice touch if you're looking at photographs, but in many other cases I want to see those nasty, hard, straight edges!
任何人都知道如何配置 UIImage
或 UIImageView
以放大具有清晰的像素边缘?那就是:让它看起来像素化,而不是模糊。
Does anyone know how you can configure a UIImage
or UIImageView
to enlarge with sharp pixel edges? That is: Let it look pixellated, not blurred.
谢谢!
推荐答案
如果要使用锐化边缘放大UIImageView中的任何图像,请使用 CALayer
的以下属性。
If you want to scale up any image in UIImageView with sharpen edge, use the following property of CALayer
.
imageview.layer.magnificationFilter = kCAFilterNearest;
似乎 magnificationFilter
会影响插值方法UIView的内容。我建议你阅读CALayer.h中对该属性的解释。
It seems that magnificationFilter
affects an interpolation method of contents of UIView. I recommend you to read an explanation of the property in 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;
我希望我的答案对你有用。
I hope that my answer is useful for you.
这篇关于在iOS中,如何在放大位图时保留锐边?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!