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

The code is as above. Granted I just learned about canvas today I have been trying to piece together code that will fit an image inside a circle to use as a marker for a map. The resultant image however looks like this:

Unfit Image

I need it to fit entirely.

1
  • 1
    I haven't tried to see if this works, but try adding fit: BoxFit.cover to your paintImage functions parameters Commented Nov 28, 2021 at 8:18

1 Answer 1

1

Adding

Fit:Boxfit.cover

to my paint image worked. Credits to @spazhead's comment.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.