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

相关推荐
消失的旧时光-19431 小时前
Flutter 插件通信架构设计:从 Channel 到 FFI 的完整边界
flutter·ffi
郑梓斌5 小时前
Luban 2 Flutter:一行代码在 Flutter 开发中实现图片压缩功能
flutter·ios
哈__5 小时前
Flutter 开发鸿蒙 PC 第一个应用:窗口创建 + 大屏布局
flutter·华为·harmonyos
AiFlutter5 小时前
蓝牙调试助手开发(03):概要设计
flutter·低代码平台·aiflutter·aiflutter低代码·flutter低代码开发·蓝牙调试·蓝牙调试助手
西西学代码6 小时前
Flutter---框架
前端·flutter
消失的旧时光-19437 小时前
Flutter 与原生通信机制全解析:MethodChannel / EventChannel / BasicMessageChannel,一篇讲透(工程级)
flutter·dart·channel
kirk_wang7 小时前
Flutter Widget核心概念深度解析
flutter·移动开发·跨平台·arkts·鸿蒙
傅里叶7 小时前
Flutter移动端获取相机内参
前端·flutter
RaidenLiu7 小时前
Offstage / Visibility:不可见真的就不消耗性能吗
前端·flutter·性能优化
火柴就是我8 小时前
学习一些常用的混合模式之BlendMode. SRC_OVER
android·flutter