学习一些常用的混合模式之BlendMode.srcOut

1 SrcOut

用途:

Keeps the source pixels that do not cover destination pixels. Discards source pixels that cover destination pixels. Discards all destination pixels.

计算公式:

测试代码:

js 复制代码
 @override
  void paint(Canvas canvas, Size size) {
    var width = size.width;
    var height = size.height;

    canvas.saveLayer(Rect.fromLTWH(0, 0, width, height), Paint());
    canvas.drawRect(
      Rect.fromLTWH(0, 0, width, height),
      Paint()..color = Colors.red.withOpacity(1), // 半透明红色
    );

    var srcPath = Path();
    srcPath.addRect(Rect.fromLTWH(width/2 - 30, height/2 - 30, 60, 60));
    var srcPaint = Paint()
      ..color = Colors.blue // 源颜色:蓝色
      ..style = PaintingStyle.stroke // 填充模式
      ..strokeWidth = 10
      ..blendMode = BlendMode.srcOut; // 混合模式
    canvas.drawPath(srcPath, srcPaint);
    canvas.restore();
  }

第一个矩形就是dst 第二个边框就是src

参考上面的公式可以得出

a = (1 - dst.a) * src.a = (1-1)*1 = 0

c = (1 - dst.a) * src.c = 0

所以混合的结果就是"00000000" 就是透明的。所以效果如下

通过修改src的alpha(透明度)属性,也可以实现不同的效果。比如改成0.7就是下面的效果。按公式计算混合区的透明度就是0.3,色值就是 blue * 0.3

相关推荐
西西学代码4 小时前
Flutter---框架
前端·flutter
消失的旧时光-19435 小时前
Flutter 与原生通信机制全解析:MethodChannel / EventChannel / BasicMessageChannel,一篇讲透(工程级)
flutter·dart·channel
kirk_wang5 小时前
Flutter Widget核心概念深度解析
flutter·移动开发·跨平台·arkts·鸿蒙
傅里叶5 小时前
Flutter移动端获取相机内参
前端·flutter
RaidenLiu5 小时前
Offstage / Visibility:不可见真的就不消耗性能吗
前端·flutter·性能优化
火柴就是我6 小时前
学习一些常用的混合模式之BlendMode. SRC_OVER
android·flutter
程序员Agions6 小时前
Flutter 邪修秘籍:那些官方文档不会告诉你的骚操作
前端·flutter
CodeOfCC9 小时前
flutter-elinux 编译linux arm64程序
linux·flutter
kirk_wang10 小时前
Flutter艺术探索-StatelessWidget与StatefulWidget区别与使用场景
flutter·移动开发·跨平台