UIImageView缩放/插值

发布于 2024-07-29 11:34:21 字数 182 浏览 2 评论 0原文

我正在开发一个小型 iPhone 应用程序,并且正在使用 UIImageView 显示图像。 我正在使用“Aspect Fit”模式放大它。 我希望在不进行插值/平滑的情况下放大图像(我希望它看起来像素化)。 有什么办法可以改变我的这种行为吗?

一个更普遍的问题是我可以实现自己的缩放算法,还是有其他内置算法可供选择?

I have a small IPhone app that I am working on and I am displaying an image with a UIImageView. I am scaling it up using the Aspect Fit mode. I would like to have the image scale up with no interpolation/smoothing (I want it to look pixellated). Is there any way I can change this behavior?

A little more general question would be can I implement my own scaling algorithm, or are there other built in ones that I can select?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

山田美奈子 2024-08-05 11:34:21

您需要将视图图层上的 magnificationFilter 属性设置为最近邻居过滤器:

[[view layer] setMagnificationFilter:kCAFilterNearest]

You would need to set the magnificationFilter property on the view's layer to the nearest neighbour filter:

[[view layer] setMagnificationFilter:kCAFilterNearest]
卸妝后依然美 2024-08-05 11:34:21

确保

#import  <QuartzCore/CALayer.h>

在包含对 setMagnificationFilter 的调用的文件顶部包含行,否则它将无法编译。

Make sure you include the line

#import  <QuartzCore/CALayer.h>

At the top of the file containing the call to setMagnificationFilter or it won't compile.

固执像三岁 2024-08-05 11:34:21

迅速

imageView.layer.magnificationFilter = kCAFilterNearest
imageView.layer.shouldRasterize = true

Swift

imageView.layer.magnificationFilter = kCAFilterNearest
imageView.layer.shouldRasterize = true
夏九 2024-08-05 11:34:21

有两种方法可以做到这一点。 您可以实现无需插值的缩放算法。 如果这需要大量工作,您可以在其他应用程序(如 gimp 或 Photoshop)中重新缩放图像。 除非您需要在应用程序中动态更改大小,否则这将起作用。

There are two ways you could do this. You can either implement a rescaling algrorithm without interpolation. If this is to much work you could rescale the image in another application like gimp or photoshop. This would work unless you needed to change the size dynamically in your application.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文