学习一些常用的混合模式之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();
  }
相关推荐
青莲8431 天前
Java并发编程高级(线程池·Executor框架·并发集合)
android·前端·面试
Android-Flutter1 天前
android compose LazyColumn 垂直列表滚动 使用
android·kotlin
程序员Agions1 天前
Flutter 邪修秘籍:那些官方文档不会告诉你的骚操作
前端·flutter
用户74589002079541 天前
Handler机制
android
福大大架构师每日一题1 天前
milvus v2.6.8 发布:搜索高亮上线,性能与稳定性全面跃升,生产环境强烈推荐升级
android·java·milvus
草莓熊Lotso1 天前
脉脉独家【AI创作者xAMA】| 开启智能创作新时代
android·java·开发语言·c++·人工智能·脉脉
李坤林1 天前
Android Binder详解【5】 ServiceManager
android·binder
Ya-Jun1 天前
Android 扫雷游戏项目设计报告
android·游戏