The source pixels are discarded, leaving the destination intact.
公式:
代码
canvas.saveLayer(Rect.fromLTWH(0, 0, width, height), Paint());
Paint dstPaint = Paint()..color = Colors.red;
dstPaint.style = ui.PaintingStyle.fill;
canvas.drawImageRect(image1!, Rect.fromLTWH(0, 0, image!.width.toDouble(), image!.height.toDouble()), Rect.fromLTWH(0, 0, width/2, height/2), dstPaint);
var srcPaint = Paint()
..color = Colors.red
..blendMode = ui.BlendMode.dst; // 源颜色:蓝色; // 混合模式
canvas.drawRect(Rect.fromLTWH(0, 0, width, height), srcPaint);
canvas.restore();
重叠部分只保留dst的内容,清空所有的src。非重叠部分只保留dst的内容,清空所有的src。所以效果就是图片全部展示,红色矩形全部不显示。
效果图如下: