extended_image
extended_image copied to clipboard
How to crop image as a circle?
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();
}
}
}
same problem here. plz~~
maybe you can use ClipRRect?