在 iOS 中,如何在放大位图时保留锐利的边缘? [英] In iOS, how do you preserve sharp edges when enlarging a bitmap?

查看:14
本文介绍了在 iOS 中,如何在放大位图时保留锐利的边缘?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当你把一个UIImage放到一个小于view的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!

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

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆