代码之家  ›  专栏  ›  技术社区  ›  satish

颤振-使用BlendMode解除常见零件的遮罩。异或

  •  2
  • satish  · 技术社区  · 6 年前

    有两个图像相互重叠, 我正在尝试使用BlendDode删除图像的公共部分。异或 但它不起作用。显示不同结果的东西。

    var s1 = Size(size.width.toDouble() / 2, size.height.toDouble() / 2);
        rect = Offset(size.width / 3, size.height / 2.30) & new Size(0.0, 0.0);
        _fittedSize = applyBoxFit(boxfit, size * 3.0, size * .9);
        inputSubrect =
            Alignment.center.inscribe(_fittedSize.source, Offset.zero & s1);
    
    outputSubrect = Alignment.center.inscribe(_fittedSize.destination, rect);
    if (imagePath != null) {
          p.blendMode = BlendMode.xor;
          canvas.drawImageRect(imagePath1, inputSubrect, outputSubrect, p);
        }
        var s2 = Size(size.width.toDouble() / 2, size.height.toDouble() / 2);
    
        rect = Offset(size.width / 3, size.height / 1.8) & new Size(0.0, 0.0);
        _fittedSize = applyBoxFit(boxfit, size * 3.0, size * .9);
        inputSubrect =
            Alignment.center.inscribe(_fittedSize.source, Offset.zero & s2);
    
        outputSubrect = Alignment.center.inscribe(_fittedSize.destination, rect);
    
        if (imagePath != null) {
          p.blendMode = BlendMode.xor;
          canvas.drawImageRect(imagePath1, inputSubrect, outputSubrect, p);
        }
    

    原始图像: enter image description here 结果我得到: enter image description here

    enter image description here

    我正在努力做到这一点:

    1 回复  |  直到 6 年前
        1
  •  0
  •   Sher Ali    6 年前

    下面的代码可能有助于解决您的问题

    Widget build(BuildContext context) {
    return new ClipPath(clipper: new PiClipper(),
    child: new Container(
      width: 150.0,
      height: 150.0,
      decoration: BoxDecoration(
          color: Colors.redAccent,
          shape: BoxShape.circle
      ),
    ),);
    }
    
    class PiClipper extends CustomClipper<Path> {
    
      @override
      Path getClip(Size size) {
      var path = Path();
      path.moveTo(0.0, 0.0);
      path.lineTo(size.width, 0.0);
      path.lineTo(size.width, size.height);
      path.lineTo(size.width/2, size.height);
      path.lineTo(size.width/2, size.height/2);
      path.lineTo(0.0, size.height/2);
      path.close();
      return path;
    }
    
    @override
    bool shouldReclip(CustomClipper<Path> oldClipper) => false;
    }
    

    above code UI