【问题标题】:How to remove a selected part of an image in Flutter?如何在 Flutter 中删除图像的选定部分?
【发布时间】:2021-01-20 04:02:04
【问题描述】:

我想将图像发送到后端,但在发送之前用户可以选择其中的一部分。我需要删除不需要的部分。下面我附上一些截图。

【问题讨论】:

    标签: image flutter image-processing


    【解决方案1】:

    经过三天的努力,我终于找到了解决方法。 因此,如果它不是橡皮擦,我只是像往常一样画画,但如果橡皮擦我用着色器替换 Paint,那是我的背景图像。

     if (!_eraser) {
        paint = new Paint()
          ..style = PaintingStyle.fill
          ..strokeCap = StrokeCap.round
          ..color = selectedColor
          ..strokeWidth = strokeWidth;
      } else {
        final Float64List deviceTransform = new Float64List(16)
          ..[0] = devicePixelRatio
          ..[5] = devicePixelRatio
          ..[10] = 1.0
          ..[15] = 2.0;
        paint = new Paint()
          ..style = PaintingStyle.fill
          ..strokeCap = StrokeCap.round
          ..shader = ImageShader(image, TileMode.repeated, TileMode.repeated, deviceTransform)
          ..strokeWidth = strokeWidth;
    

    绘画课

    @override
      void paint(Canvas canvas, Size size) {
        canvas.drawImage(image, Offset.zero, new Paint());
    
        for (int i = 0; i < pointsList.length - 1; i++) {
          if (pointsList[i] != null && pointsList[i + 1] != null) {
            canvas.drawLine(pointsList[i].points, pointsList[i + 1].points, pointsList[i].paint);
    
          } else if (pointsList[i] != null && pointsList[i + 1] == null) {
            offsetPoints.clear();
             offsetPoints.add(pointsList[i].points);
             offsetPoints.add(Offset(pointsList[i].points.dx + 0.1, pointsList[i].points.dy + 0.1));
             canvas.drawCircle(pointsList[i].points, pointsList[i].paint.strokeWidth / 2, pointsList[i].paint);
          }
        }
      }
      
    

    【讨论】:

    • 你能发一张图片或 gif 来说明它的工作原理吗?
    【解决方案2】:

    如果您想根据已有的用户输入裁剪图像,可以使用image 库中的copyCrop 函数。

    【讨论】:

    • 我不想裁剪,我想删除不需要的部分并保持大小,比如橡皮擦
    • 您想完全实现您在屏幕截图中所做的事情吗?如果不能,您能否添加您想要的最终图像的屏幕截图(已删除部分的图像)?
    • 嘿,抱歉,我还没有做的事情迟到了,但我正在努力
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-29
    • 1970-01-01
    • 2019-12-17
    • 1970-01-01
    相关资源
    最近更新 更多