Flutter 图片缩放和裁剪插件

一个简单易用的 Flutter 插件,用于在 iOS 和 Android 上裁剪图片。

rect

circle

安装

pubspec.yaml 中将 simple_image_crop simple_image_crop 添加为 依赖项

使用方法

创建一个加载和编辑图片的 widget

final imgCropKey = GlobalKey<CropState>();

Widget _buildCropImage() {
  return Container(
      color: Colors.black,
      child: ImgCrop(
        key: cropKey,
        chipRadius: 150,  // crop area radius
        chipShape: 'circle', // crop type "circle" or "rect"
        image: Image.file(imageFile), // you selected image file
      ),
  );
}

生成裁剪后的图片

  • 推荐使用 image-picker 选择图片,图片文件可能来自前一页
    final Map args = ModalRoute.of(context).settings.arguments
  • 一个 async 函数来获取裁剪后的图片文件
    crop.cropCompleted('选定的图片文件', {pictureQuality: '图片质量的 int 值'})
floatingActionButton: FloatingActionButton(
  onPressed: () async {
    final crop = cropKey.currentState;
    final croppedFile =
        await crop.cropCompleted(args['image'], pictureQuality: 900);

    // show you croppedFile ……
    showImage(context, croppedFile);
  },

GitHub

https://github.com/lijungegea/flutter_simple_image_crop