本文介绍了如何在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上实现方块或高斯模糊的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 07:19