0
final ui.PictureRecorder pictureRecorder = ui.PictureRecorder();
final Canvas canvas = Canvas(pictureRecorder);
final Paint paint = Paint()..color;
final double radius = size / 2;
final Path clipPath = Path();
clipPath.addRRect(RRect.fromRectAndRadius(
    Rect.fromLTWH(0, 0, size.toDouble(), size.toDouble()),
    Radius.circular(100)));
canvas.clipPath(clipPath);
final Uint8List imageUint8List =
    await (await NetworkAssetBundle(Uri.parse(src)).load(src))
        .buffer
        .asUint8List();
final ui.Codec codec = await ui.instantiateImageCodec(imageUint8List);
final ui.FrameInfo imageFI = await codec.getNextFrame();
paintImage(
    canvas: canvas,
    rect: Rect.fromLTWH(0, 0, size.toDouble(), size.toDouble()),
    image: imageFI.image);
if (addBorder) {
  //draw Border
  paint..color = borderColor;
  paint..style = PaintingStyle.stroke;
  paint..strokeWidth = borderSize;
  canvas.drawCircle(Offset(radius, radius), radius, paint);
}
final _image = await pictureRecorder
    .endRecording()
    .toImage(size, (size * 1.1).toInt());
final rdata = await _image.toByteData(format: ui.ImageByteFormat.png);

代码如上。当然,我今天刚刚了解了画布,我一直在尝试拼凑代码,这些代码将适合一个圆圈内的图像用作地图的标记。然而,生成的图像如下所示:

不合适的图像

我需要它完全适合。

4

1 回答 1

0

添加

Fit:Boxfit.cover

到我的油漆图像工作。归功于@spazhead 的评论。

于 2021-11-28T10:01:10.290 回答