颤音:用drawnlines使用定制器绘制图像

发布于 2025-01-27 00:23:31 字数 1165 浏览 2 评论 0原文

我正在处理的应用程序的一部分涉及编辑照片。我试图包括一个绘制图像的选项。我找不到有关如何在Github或文档上执行此操作的任何示例。

这就是我到目前为止所拥有的:

class Sketcher extends CustomPainter {
  final List<DrawnLine> lines;
  final ui.Image image;
  final BuildContext context;

  Sketcher({required this.lines, required this.image,});


  @override
  void paint(Canvas canvas, Size size) {
    Paint paint = Paint()
      ..color = Colors.redAccent
      ..strokeCap = StrokeCap.round
      ..strokeWidth = 5.0;




    for (int i = 0; i < lines.length; ++i) {
      if (lines[i] == null) continue;
      for (int j = 0; j < lines[i].path.length - 1; ++j) {
        if (lines[i].path[j] != null && lines[i].path[j + 1] != null) {
          paint.color = lines[i].color;
          paint.strokeWidth = lines[i].width;
          canvas.drawLine(lines[i].path[j], lines[i].path[j + 1], paint);
        }
      }
    }

// Add DrawnLine to image
  }

  @override
  bool shouldRepaint(Sketcher oldDelegate) {
    return true;
  }
}

目前,我正在stack窗口小部件中显示图像上的绘制线路。

是否可以通过修改图像的线条将画布与图像结合在一起?

我已经知道canvas.drawimage(),但是我还没有找到任何有效的代码,也没有人在网上在任何地方都有类似的问题。

A part of an application I am working on involves editing photos. I am attempting to include an option to draw on an image. I can not find any examples of how to do this on Github or with the documentation.

This is what I have so Far:

class Sketcher extends CustomPainter {
  final List<DrawnLine> lines;
  final ui.Image image;
  final BuildContext context;

  Sketcher({required this.lines, required this.image,});


  @override
  void paint(Canvas canvas, Size size) {
    Paint paint = Paint()
      ..color = Colors.redAccent
      ..strokeCap = StrokeCap.round
      ..strokeWidth = 5.0;




    for (int i = 0; i < lines.length; ++i) {
      if (lines[i] == null) continue;
      for (int j = 0; j < lines[i].path.length - 1; ++j) {
        if (lines[i].path[j] != null && lines[i].path[j + 1] != null) {
          paint.color = lines[i].color;
          paint.strokeWidth = lines[i].width;
          canvas.drawLine(lines[i].path[j], lines[i].path[j + 1], paint);
        }
      }
    }

// Add DrawnLine to image
  }

  @override
  bool shouldRepaint(Sketcher oldDelegate) {
    return true;
  }
}

At the moment I am displaying the Drawn Lines over the Image in a Stack Widget.

Is there a way to combine the canvas with the Image by amending the lines to the Image?

I already know about canvas.drawImage() however I haven't found any code that works and no one is having a similar issue anywhere online.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文