extended_image icon indicating copy to clipboard operation
extended_image copied to clipboard

How to crop image as a circle?

Open ember11498 opened this issue 1 year ago • 2 comments

I have asked this before but I got a vague response. After reading the example I still could not crop the image correctly as a circle. Can anyone point what how to have a circle editor crop layer that actually crops a circle?

class CircleEditorCropLayerPainter extends EditorCropLayerPainter {
const CircleEditorCropLayerPainter();

@override
void paintCorners(
    Canvas canvas, Size size, ExtendedImageCropLayerPainter painter) {
  final Paint paint = Paint()
    ..color = painter.cornerColor
    ..style = PaintingStyle.fill;
  final Rect cropRect = painter.cropRect;
  const double radius = 6;
  canvas.drawCircle(Offset(cropRect.left, cropRect.top), radius, paint);
  canvas.drawCircle(Offset(cropRect.right, cropRect.top), radius, paint);
  canvas.drawCircle(Offset(cropRect.left, cropRect.bottom), radius, paint);
  canvas.drawCircle(Offset(cropRect.right, cropRect.bottom), radius, paint);
}

@override
void paintMask(
    Canvas canvas, Size size, ExtendedImageCropLayerPainter painter) {
  final Rect rect = Offset.zero & size;
  final Rect cropRect = painter.cropRect;
  final Color maskColor = painter.maskColor;
  canvas.saveLayer(rect, Paint());
  canvas.drawRect(
      rect,
      Paint()
        ..style = PaintingStyle.fill
        ..color = maskColor);
  canvas.drawCircle(cropRect.center, cropRect.width / 2.0,
      Paint()..blendMode = BlendMode.clear);
  canvas.restore();
}

@override
void paintLines(
    Canvas canvas, Size size, ExtendedImageCropLayerPainter painter) {
  final Rect cropRect = painter.cropRect;
  if (painter.pointerDown) {
    canvas.save();
    canvas.clipPath(Path()..addOval(cropRect));
    super.paintLines(canvas, size, painter);
    canvas.restore();
  }
}
}

ember11498 avatar Jan 24 '24 09:01 ember11498

same problem here. plz~~

rambozzang avatar Feb 06 '24 15:02 rambozzang

maybe you can use ClipRRect?

Darkildo avatar May 13 '24 04:05 Darkildo