Akshay Jaiswal
Akshay Jaiswal

Reputation: 193

Crop Image before capturing image from camera plugin in flutter

I am using camera plugin to capture image, in flutter. But I want to crop the image from bottom and top to upload only that part.

Upvotes: 0

Views: 3214

Answers (1)

You can use image_cropper Library after capture image

import 'package:image_cropper/image_cropper.dart';

File croppedFile = await ImageCropper.cropImage(
  sourcePath: imageFile.path,
  aspectRatioPresets: [
    CropAspectRatioPreset.square,
    CropAspectRatioPreset.ratio3x2,
    CropAspectRatioPreset.original,
    CropAspectRatioPreset.ratio4x3,
    CropAspectRatioPreset.ratio16x9
  ],
  androidUiSettings: AndroidUiSettings(
      toolbarTitle: 'Cropper',
      toolbarColor: Colors.deepOrange,
      toolbarWidgetColor: Colors.white,
      initAspectRatio: CropAspectRatioPreset.original,
      lockAspectRatio: false),
  iosUiSettings: IOSUiSettings(
    minimumAspectRatio: 1.0,
  )
);

Optional parameters

  • maxWidth: maximum cropped image width.
  • maxHeight: maximum cropped image height.

  • aspectRatio: controls the aspect ratio of crop bounds. If this values is set, the cropper is locked and user can't change the aspect ratio of crop bounds.

  • aspectRatioPresets: controls the list of aspect ratios in the crop menu view. In Android, you can set the initialized aspect ratio when starting the cropper by setting the value of AndroidUiSettings.initAspectRatio.

  • cropStyle: controls the style of crop bounds, it can be rectangle or circle style (default is CropStyle.rectangle).

  • compressFormat: the format of result image, png or jpg (default is ImageCompressFormat.jpg).

  • compressQuality: the value [0 - 100] to control the quality of image compression.

  • androidUiSettings: controls UI customization on Android. See Android customization.

  • iosUiSettings: controls UI customization on iOS. See iOS customization.

Upvotes: 1

Related Questions