学习一些常用的混合模式之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();
  }
相关推荐
右手吉他4 小时前
高通平台IA APN问题分析之二
android·物联网
夜雪一千5 小时前
MySQL 自增 ID 的底层原理与坑点
android·mysql·adb
不浪费一个字节5 小时前
一个纯 Python 实现的 APK 解析与设备操控工具箱
android
itmigrate5 小时前
PHP 导出大 CSV 时内存溢出的一次排查
android·开发语言·php
hai_android5 小时前
LiveEventBusCore 跨 Activity 通讯源码解析
android·kotlin·android jetpack
维克兜率天6 小时前
【维克】统计套利建模:从因子到信号的完整流程
android·开发语言·python·算法·kotlin
FungLeo6 小时前
成为全栈·Flutter App 篇·Markdown 编辑器:编辑、预览与离开保护
flutter·移动开发·markdown编辑器·表单设计·成为全栈·草稿保存
hunterandroid6 小时前
Room 数据库迁移与多表关联查询实战
android
吐了啊取名字太难6 小时前
Android 相机 USB 连接别写在 Activity 里:锁屏、切页和后台传输怎么设计?
android·数码相机