2014-04-04 51 views
1

當您將UIImage放入小於視圖的UIImageView,並且視圖的內容模式爲ScaleToFit時,iOS會按預期放大位圖。我從未想到的是,它模糊了它擴大的像素的邊緣。我可以看到,如果你正在看照片,這可能是一個很好的接觸,但在許多其他情況下,我想看到那些討厭,硬,直線的邊緣!在iOS中,如何在放大位圖時保留尖銳的邊緣?

是否有人知道如何配置一個UIImageUIImageView放大與銳利的像素邊緣?那就是:讓它看起來像素化,而不是模糊。

謝謝!

+0

您可以根據圖像視圖的寬度和高度調整圖像大小。 –

+0

非常感謝Kyokook!我一直想知道如何做這個多年! –

回答

3

如果要用銳化邊緣放大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; 

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

+0

這很好,達到了我的目的,但是我想問一下,當我使用'magnificationFilter = kCAFilterNearest'時,真正的圖像原始像素是被放大的大而銳利的像素,還是隻是由某些處理產生的?謝謝! – Suge