Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to crop image as a circle? #653

Open
ember11498 opened this issue Jan 24, 2024 · 2 comments
Open

How to crop image as a circle? #653

ember11498 opened this issue Jan 24, 2024 · 2 comments

Comments

@ember11498
Copy link

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();
  }
}
}
@rambozzang
Copy link

same problem here. plz~~

@Darkildo
Copy link

maybe you can use ClipRRect?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants