飞镖(Flutter)canvas.drawImageRect:绘制圆形图片

时间:2019-10-30 15:18:27

标签: flutter dart

我正在尝试将图像转换为Uint8List。

这是我的代码:

  Future<Uint8List> getBytesFromCanvas(int width, int height, urlAsset) async {
    final ui.PictureRecorder pictureRecorder = ui.PictureRecorder();
    final Canvas canvas = Canvas(pictureRecorder);

    final ByteData datai = await rootBundle.load(urlAsset);
    var imaged = await loadImage(new Uint8List.view(datai.buffer));
    canvas.drawImageRect(
      imaged,
      Rect.fromLTRB(
          100, 100, imaged.width.toDouble(), imaged.height.toDouble()),
      Rect.fromCircle(center: new Offset(100, 100), radius: 100),
      new Paint(),
    );

    final img = await pictureRecorder.endRecording().toImage(width, height);
    final data = await img.toByteData(format: ui.ImageByteFormat.png);
    return data.buffer.asUint8List();
  }

这给出一个矩形的Image而不是一个圆形的Image。 我在做什么错了?

非常感谢您!

0 个答案:

没有答案