如何绘制标记?就像使用画布的Google地图中的标记

时间:2020-05-23 14:04:51

标签: flutter canvas dart marker google-maps-flutter

我需要使用画布 DRAW (自定义标记),到目前为止,我绘制了逆三角形形状。您是否有关于如何绘制标记形状的想法?

class DrawTriangle extends CustomPainter {

      Paint _paint;

      DrawTriangle() {
        _paint = Paint()
          ..color = Colors.green
          ..style = PaintingStyle.fill;
      }

      @override
      void paint(Canvas canvas, Size size) {
        var path = Path();
        path.moveTo(size.width, size.height);
        path.lineTo(size.width + 100, size.height - 100);
        path.lineTo(size.width - 100, size.height - 100);
        path.close();
        canvas.drawPath(path, _paint);
      }

      @override
      bool shouldRepaint(CustomPainter oldDelegate) {
        return false;
      }
    }
    Future<Uint8List> getBytesFromCanvas(
          int width, int height, Color color) async {
        final PictureRecorder pictureRecorder = PictureRecorder();
        final Canvas canvas = Canvas(pictureRecorder);
        CustomPainter painter = DrawTriangle();
        painter.paint(canvas, Size(100.0,100.0));
        final img = await pictureRecorder.endRecording().toImage(width, height);
        final data = await img.toByteData(format: ImageByteFormat.png);
        return data.buffer.asUint8List();
      }

以上方法创建逆三角形,我需要创建标记形状。 我该如何实现?

1 个答案:

答案 0 :(得分:0)

为什么要使用自定义绘画工具,也可以将图像用于同一任务。我为您找到了this条文章。希望我能帮到你。