如何在Flutter中删除图像的选定部分? [英] How to remove a selected part of an image in Flutter?

查看:126
本文介绍了如何在Flutter中删除图像的选定部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to send an image to backend, but before sending user can select some part of it. And I need to remove unwanted part. Below I attached some screenshots.

推荐答案

经过三天的研究,我终于找到解决方法.因此,如果不是橡皮擦,我将像往常一样绘制,但是如果将橡皮擦替换为Painter,则橡皮擦是我的背景图像.

After three days of working on it I finally found out, how to work around. So if it's not an eraser I'm just drawing as always but if an eraser I'm replacing Paint with shader wich is my image from background.

 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);
      }
    }
  }
  

这篇关于如何在Flutter中删除图像的选定部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆