学习一些常用的混合模式之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 所以图片就看起来有点泛红。效果图如下:

相关推荐
传奇开心果编程8 小时前
【Flutter入门练中学】第8课:动画与过渡
android·学习·flutter·ui·ios
传奇开心果编程10 小时前
【Flutter入门练中学】第11课:状态管理进阶与声明式路由
android·学习·flutter·ui·ios
陆断枫10 小时前
Flutter 列表性能优化
flutter
恋猫de小郭11 小时前
Flutter 多窗口重要优化合并,多窗口性能和实用性大幅提升
android·前端·flutter
gnip18 小时前
Flutter 原生插件开发实战指南
前端·flutter
chenyin1 天前
Flutter 架构设计:Feature-First 与 Pub workspaces
flutter
gnip1 天前
GetX 在 Flutter 中的使用:两种视图管理方式解析
前端·flutter
程序员老刘1 天前
Flutter版本选择指南:9月大限落地,3.47一个月连发四补丁 | 2026年9月
flutter·ai编程·客户端
zeqinjie1 天前
Flutter 获取 iPhone Duo 预留区位置
前端·flutter·ios
恋猫de小郭1 天前
Flutter Golden Tests:给 AI Agent 的 UI 测试系统
android·前端·flutter