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

The source pixels are drawn over the destination pixels.

公式:

在dst.a = 1 的情况下, a = 1 ,c = src.c + (1-src.a)*dst.c, 这个可以用来两张图片的切换。效果图如下:

上面的是通过两张图片叠加修改透明度的方式,下面的是通过src_over 混合方式,可以看出下面的方式更柔和一点。

关键代码:

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.drawImageRect(image1!, Rect.fromLTWH(0, 0, image!.width.toDouble(), image!.height.toDouble()), Rect.fromLTWH(0, 0, width, height), dstPaint);



    var srcPaint = Paint()
      ..color = Colors.blue.withOpacity(listener.value) // 源颜色:蓝色
      ..style = PaintingStyle.stroke // 填充模式
      ..strokeWidth = 70
      ..blendMode = BlendMode.srcOver; // 混合模式
    // 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();
  }
相关推荐
浮芷.2 小时前
Flutter 框架跨平台鸿蒙开发 - AR动物互动应用
flutter·ar·harmonyos
SharpCJ2 小时前
Android 开发者为什么必须掌握 AI 能力?端侧视角下的技术变革
android·ai·aigc
_李小白3 小时前
【OSG学习笔记】Day 38: TextureVisitor(纹理访问器)
android·笔记·学习
JJay.3 小时前
Kotlin 高阶函数学习指南
android·开发语言·kotlin
jinanwuhuaguo3 小时前
截止到4月8日,OpenClaw 2026年4月更新深度解读剖析:从“能力回归”到“信任内建”的范式跃迁
android·开发语言·人工智能·深度学习·kotlin
加农炮手Jinx3 小时前
Flutter 组件 conventional 适配鸿蒙 HarmonyOS 实战:约定式提交标准,构建自动化版本治理与 CI/CD 质量治理架构
flutter·harmonyos·鸿蒙·openharmony
王码码20353 小时前
Flutter 三方库 appstream 的鸿蒙化适配指南 - 驾驭 Linux 生态元数据规范,打造高性能、标准化、国际化的 OpenHarmony 桌面应用商店分发基石
flutter·harmonyos·鸿蒙·openharmony
见山是山-见水是水3 小时前
Flutter 框架跨平台鸿蒙开发 - AR植物养护助手
flutter·华为·ar·harmonyos
JJay.3 小时前
Android Kotlin 协程使用指南
android·开发语言·kotlin
autumn20054 小时前
Flutter 框架跨平台鸿蒙开发 - 历史人物对话
服务器·flutter·华为·harmonyos