autojs-高斯滤镜BlurMaskFilter

简介: autojs-高斯滤镜BlurMaskFilter

微信图片_20220626131326.gif

"ui";
/*
 * @version: 1.0
 * @Date: 2021-08-15 15:43:57
 * @LastEditTime: 2021-08-15 19:20:02
 * @LastEditors: 牙叔
 * @Description: BlurMaskFilter
 * @FilePath: \autojs-test\main.js
 * @名人名言: 牙叔教程 简单易懂
 * @bilibili: 牙叔教程
 * @公众号: 牙叔教程
 * @QQ群: 747748653
 */
//NORMAL: 内外都模糊绘制
//SOLID: 内部正常绘制,外部模糊
//OUTER: 内部不绘制,外部模糊
//INNER: 内部模糊,外部不绘制
engines.all().map((ScriptEngine) => {
  if (engines.myEngine().toString() !== ScriptEngine.toString()) {
    ScriptEngine.forceStop();
  }
});
importClass(android.graphics.Color);
importClass(android.graphics.Path);
importClass(android.graphics.Paint);
importClass(android.graphics.BlurMaskFilter);
importClass(android.view.MotionEvent);
importClass(android.view.View);
(function () {
  util.extend(CustomView, ui.Widget);
  function CustomView() {
    ui.Widget.call(this);
    let BlurMaskFilterBlurStyle = BlurMaskFilter.Blur.NORMAL;
    this.defineAttr("BlurMaskFilterBlurStyle", (view, attr, value, defineSetter) => {
      switch (value) {
        case "NORMAL":
          value = BlurMaskFilter.Blur.NORMAL;
          break;
        case "SOLID":
          value = BlurMaskFilter.Blur.SOLID;
          break;
        case "OUTER":
          value = BlurMaskFilter.Blur.OUTER;
          break;
        case "INNER":
          value = BlurMaskFilter.Blur.INNER;
          break;
        default:
          value = BlurMaskFilter.Blur.NORMAL;
          break;
      }
      BlurMaskFilterBlurStyle = value;
    });
    let _radius = 1;
    let paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(Color.RED);
    this.render = function () {
      return JavaAdapter(
        View,
        {
          onMeasure: function (widthMeasureSpec, heightMeasureSpec) {
            this.setMeasuredDimension(230, 230);
          },
          onDraw: function (canvas) {
            if (_radius < 1) {
              _radius = 1;
            }
            paint.setMaskFilter(new BlurMaskFilter(_radius, BlurMaskFilterBlurStyle));
            this.setLayerType(1, null);
            canvas.drawRect(
              0 + this.getWidth() / 3,
              0 + this.getHeight() / 3,
              (this.getWidth() / 3) * 2,
              (this.getHeight() / 3) * 2,
              paint
            );
          },
          setRadius: function (radius) {
            _radius = radius;
            this.invalidate();
          },
        },
        activity
      );
    };
  }
  ui.registerWidget("custom-view", CustomView);
  return CustomView;
})();
ui.layout(
  <vertical>
    <text text="牙叔教程 简单易懂" textSize="28sp" textColor="#fbfbfe" bg="#00afff" w="*" gravity="center"></text>
    <seekbar id="seekbar" margin="9"></seekbar>
    <vertical gravity="center_horizontal">
      <text text="NORMAL" w="*" gravity="center" margin="6"></text>
      <custom-view id="customView" BlurMaskFilterBlurStyle="NORMAL" />
      <text text="SOLID" w="*" gravity="center" margin="6"></text>
      <custom-view id="customView1" BlurMaskFilterBlurStyle="SOLID" />
      <text text="OUTER" w="*" gravity="center" margin="6"></text>
      <custom-view id="customView2" BlurMaskFilterBlurStyle="OUTER" />
      <text text="INNER" w="*" gravity="center" margin="6"></text>
      <custom-view id="customView3" BlurMaskFilterBlurStyle="INNER" />
    </vertical>
  </vertical>
);
ui.seekbar.setOnSeekBarChangeListener(
  new android.widget.SeekBar.OnSeekBarChangeListener({
    onProgressChanged(seekBar, progress, fromUser) {
      ui.customView.setRadius(progress);
      ui.customView1.setRadius(progress);
      ui.customView2.setRadius(progress);
      ui.customView3.setRadius(progress);
    },
  })
);


名人名言

思路是最重要的, 其他的百度, bing, stackoverflow, 安卓文档, autojs文档, 最后才是群里问问

--- 牙叔教程


声明

部分内容来自网络

本教程仅用于学习, 禁止用于其他用途

相关文章
|
C++ 计算机视觉
OpenCV-人像—酷感冷艳滤镜
OpenCV-人像—酷感冷艳滤镜
|
前端开发 数据可视化 测试技术
autojs裁剪找图
牙叔教程 简单易
294 0
|
4月前
|
前端开发 容器
Flutter图片处理之高斯模糊
Flutter图片处理之高斯模糊
179 1
|
7月前
|
计算机视觉 开发者 Python
OpenCV中图像的缩放与旋转讲解及实战演示(附Python源码)
OpenCV中图像的缩放与旋转讲解及实战演示(附Python源码)
165 0
OpenCV-怀旧色滤镜
OpenCV-怀旧色滤镜
100 1
C++-基于参考灰度图上色GrayToColorFromOther
C++-基于参考灰度图上色GrayToColorFromOther
|
计算机视觉 C++ Python
Python相片图片编辑工具-翻转旋转亮度磨皮裁剪添加文字
这篇博客针对<<Python相片图片编辑工具-翻转旋转亮度磨皮裁剪添加文字>>编写代码,代码整洁,规则,易读。 学习与应用推荐首选。
113 0
|
算法
实现怀旧滤镜与连环画滤镜---OpenCV-Python开发指南(48)
实现怀旧滤镜与连环画滤镜---OpenCV-Python开发指南(48)
219 0
实现怀旧滤镜与连环画滤镜---OpenCV-Python开发指南(48)
|
JavaScript 算法 开发工具
autojs人像变换
autojs人像变换
274 0