HarmonyOS 如何实现高斯模糊?

如何实现高斯模糊,对图片的高斯模糊和对纯背景色的组件模糊,下面的效果不是很明显

Row()
  .width(200)
  .height(200)
  .backgroundColor($r('app.color.black'))
  .opacity(0.8)
  .backdropBlur(20)
阅读 498
1 个回答

导入图像处理(@ohos.multimedia.image)和图像效果(@ohos.effectKit)模块,对图像进行处理并添加模糊效果,参考链接https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-effectkit-V5\#blur

import image from "@ohos.multimedia.image";
import effectKit from "@ohos.effectKit";

const color = new ArrayBuffer(96);
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } };
image.createPixelMap(color, opts).then((pixelMap) => {
  let radius = 5;
  let headFilter = effectKit.createEffect(pixelMap);
  if (headFilter != null) {
    headFilter.blur(radius);
  } 
}
)

背景模糊还是推荐使用backdropBlur