I'm trying to crop a File (imagefile) in flutter. This is what I have:
This is what I would like to get after crop (a png with circle crop)
It's important that the file is png, so it doesn't have white borders.
Is there a package that support this?
I'm trying to crop a File (imagefile) in flutter. This is what I have:
This is what I would like to get after crop (a png with circle crop)
It's important that the file is png, so it doesn't have white borders.
Is there a package that support this?
You can use BoxDecoration to crop the image to be displayed on the Widget.
Container(
width: 150,
height: 150,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.white,
image: DecorationImage(
fit: BoxFit.fill,
image: AssetImage('assets/image.jpeg'),
),
),
),
These simple steps get the required result.
Create a PictureRecorder.
Create a Canvas with your PictureRecorder.
Draw circle in canvas using canvas.drawCircle().
Call endRecording() on the PictureRecorder to get a Picture.
Call toImage() on the Picture.
Convert image toByteData() .
Save image locally using getApplicationDocumentsDirectory() ,only if you want to save.
Use this simple image cropping package Which supports cropping the actual file.
You can also refer to my answer on rotating images in files using dart.