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

SRC_ATOP

Discards the source pixels that do not cover destination pixels. Draws remaining source pixels over destination pixels.

计算公式:

在src.a 跟 dst.a 都是1的情况下,整体效果跟srcIn一样。

但是当dst.a = 1 的时候颜色值就是 src.a 从0-1变化的时候 就是src.c + src.dst * (1 - src.a)

例子:

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());
    Paint dstPaint = Paint()..color = Colors.red;
    dstPaint.strokeWidth = 20;
    dstPaint.style = PaintingStyle.stroke;

    canvas.drawCircle(Offset(width/2,height/2), 10, dstPaint);

    canvas.drawCircle(Offset(width/2,height/2), 50, dstPaint);

    canvas.drawCircle(Offset(width/2,height/2), 90, dstPaint);

    canvas.drawCircle(Offset(width/2,height/2), 130, dstPaint);

    var srcPaint = Paint()
      ..color = Colors.blue.withOpacity(0.5) // 源颜色:蓝色
      ..style = PaintingStyle.stroke // 填充模式
      ..strokeWidth = 70
      ..blendMode = BlendMode.srcATop; // 混合模式
    // canvas.drawRect(Rect.fromLTWH(0, 0, width, height), srcPaint);
    canvas.drawImageRect(image!, Rect.fromLTWH(0, 0, image!.width.toDouble(), image!.height.toDouble()), Rect.fromLTWH(0, 0, width, height), srcPaint);
    canvas.restore();
  }

这里src.a = 0.5 相当于在src.c中混入了 0.5*dst.c 所以图片就看起来有点泛红。效果图如下:

相关推荐
程序员老刘·19 小时前
Android Studio Otter 3 发布:日常开发选AS还是Cursor?
flutter·android studio·ai编程·跨平台开发·客户端开发
浩辉_19 小时前
Dart - 内存管理与垃圾回收(GC)深度解析
flutter·dart
一起养小猫21 小时前
Flutter for OpenHarmony 实战:记忆棋游戏完整开发指南
flutter·游戏·harmonyos
Betelgeuse761 天前
【Flutter For OpenHarmony】TechHub技术资讯界面开发
flutter·ui·华为·交互·harmonyos
铅笔侠_小龙虾1 天前
Flutter 安装&配置
flutter
mocoding1 天前
使用已经完成鸿蒙化适配的Flutter本地持久化存储三方库shared_preferences让你的应用能够保存用户偏好设置、缓存数据等
flutter·华为·harmonyos·鸿蒙
无熵~1 天前
Flutter入门
flutter
hudawei9961 天前
要控制动画的widget为什么要with SingleTickerProviderStateMixin
flutter·mixin·with·ticker·动画控制
jian110581 天前
flutter dio 依赖,dependencies 和 dev_dependencies的区别
flutter
王码码20351 天前
Flutter for OpenHarmony 实战之基础组件:第十七篇 滚动进阶 ScrollController 与 Scrollbar
flutter·harmonyos