如何在 iOS 上实现方框或高斯模糊 [英] How to implement a box or gaussian blur on iOS

查看:34
本文介绍了如何在 iOS 上实现方框或高斯模糊的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够拍摄图像并相对较快地对其进行模糊处理(比如在 0.1 秒内).图片尺寸几乎不会超过 256 x 256 像素.

I want to be able to take an image and blur it relatively quickly (say in 0.1 sec). Image size would almost never be larger than 256 x 256 px.

我是否必须遍历每个像素并将它们与邻居平均,或者是否有更高级别的方法可以做到这一点?

Do I have to loop thru every pixel and average them with neighbors or is there a higher-level way that I could do this?

PS:我知道多个框模糊可以近似高斯模糊.

PS: I am aware that multiple box blurs can approximate a gaussian blur.

推荐答案

我发现了一个非常快速且非常糟糕的 iOS3.2+ 应用程序

I found a really fast pretty crappy way for iOS3.2+ apps

  UIView *myView = [self view];
  CALayer *layer = [myView layer];
  [layer setRasterizationScale:0.25];
  [layer setShouldRasterize:YES];

这会将视图栅格化为 4x4 像素块,然后使用双线性过滤将其放大...它非常快,如果您只想模糊模态视图下的背景视图,它看起来还可以.

This rasterizes the view down to 4x4 pixel chunks then scales it back up using bilinear filtering... it's EXTREMELY fast and looks ok if you are just wanting to blur a background view under a modal view.

要撤消它,只需将光栅化比例设置回 1.0 或关闭光栅化.

To undo it, just set the rasterization scale back to 1.0 or turn off rasterization.

这篇关于如何在 iOS 上实现方框或高斯模糊的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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