1 Star 0 Fork 0

王智鹏/flutter_image_cropper

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
BSD-3-Clause

Image Cropper

pub package

A Flutter plugin for Android and iOS supports cropping images. This plugin is based on two different native libraries so it comes with different UI between these platforms.

Introduction

Image Cropper doesn't manipulate images in Dart codes directly, instead, the plugin uses Platform Channel to expose Dart APIs that Flutter application can use to communicate with two very powerful native libraries (uCrop and TOCropViewController) to crop and rotate images. Because of that, all credits belong to these libraries.

uCrop - Yalantis

GitHub watchers GitHub stars GitHub forks License

This project aims to provide an ultimate and flexible image cropping experience. Made in Made in Yalantis

TOCropViewController - TimOliver

GitHub watchers GitHub stars GitHub forks Version GitHub license

TOCropViewController is an open-source UIViewController subclass to crop out sections of UIImage objects, as well as perform basic rotations. It is excellent for things like editing profile pictures, or sharing parts of a photo online. It has been designed with the iOS Photos app editor in mind, and as such, behaves in a way that should already feel familiar to users of iOS.

How to install

Android

  • Add UCropActivity into your AndroidManifest.xml
<activity
    android:name="com.yalantis.ucrop.UCropActivity"
    android:screenOrientation="portrait"
    android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>

Note:

From v1.2.0, you need to migrate your android project to v2 embedding (detail)

iOS

  • No configuration required

Usage

Required paramsters

  • sourcePath: the absolute path of an image file.

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.

Note

The result file is saved in NSTemporaryDirectory on iOS and application Cache directory on Android, so it can be lost later, you are responsible for storing it somewhere permanent (if needed).

Customization

Android

Image Cropper provides a helper class called AndroidUiSettings that wraps all properties can be used to customize UI in uCrop library.

Property Description Type
toolbarTitle desired text for Toolbar title String
toolbarColor desired color of the Toolbar Color
statusBarColor desired color of status Color
toolbarWidgetColor desired color of Toolbar text and buttons (default is darker orange) Color
backgroundColor desired background color that should be applied to the root view Color
activeControlsWidgetColor desired resolved color of the active and selected widget and progress wheel middle line (default is white) Color
dimmedLayerColor desired color of dimmed area around the crop bounds Color
cropFrameColor desired color of crop frame Color
cropGridColor desired color of crop grid/guidelines Color
cropFrameStrokeWidth desired width of crop frame line in pixels int
cropGridRowCount crop grid rows count int
cropGridColumnCount crop grid columns count int
cropGridStrokeWidth desired width of crop grid lines in pixels int
showCropGrid set to true if you want to see a crop grid/guidelines on top of an image bool
lockAspectRatio set to true if you want to lock the aspect ratio of crop bounds with a fixed value (locked by default) bool
hideBottomControls set to true to hide the bottom controls (shown by default) bool
initAspectRatio desired aspect ratio is applied (from the list of given aspect ratio presets) when starting the cropper CropAspectRatioPreset

iOS

Image Cropper provides a helper class called IOUiSettings that wraps all properties can be used to customize UI in TOCropViewController library.

Property Description Type
minimumAspectRatio The minimum croping aspect ratio. If set, user is prevented from setting cropping rectangle to lower aspect ratio than defined by the parameter double
rectX The initial rect of cropping: x. double
rectY The initial rect of cropping: y. double
rectWidth The initial rect of cropping: width. double
rectHeight The initial rect of cropping: height. double
showActivitySheetOnDone If true, when the user hits 'Done', a UIActivityController will appear before the view controller ends bool
showCancelConfirmationDialog Shows a confirmation dialog when the user hits 'Cancel' and there are pending changes (default is false) bool
rotateClockwiseButtonHidden When disabled, an additional rotation button that rotates the canvas in 90-degree segments in a clockwise direction is shown in the toolbar (default is false) bool
hidesNavigationBar If this controller is embedded in UINavigationController its navigation bar is hidden by default. Set this property to false to show the navigation bar. This must be set before this controller is presented bool
rotateButtonsHidden When enabled, hides the rotation button, as well as the alternative rotation button visible when showClockwiseRotationButton is set to YES (default is false) bool
resetButtonHidden When enabled, hides the 'Reset' button on the toolbar (default is false) bool
aspectRatioPickerButtonHidden When enabled, hides the 'Aspect Ratio Picker' button on the toolbar (default is false) bool
resetAspectRatioEnabled If true, tapping the reset button will also reset the aspect ratio back to the image default ratio. Otherwise, the reset will just zoom out to the current aspect ratio. If this is set to false, and aspectRatioLockEnabled is set to true, then the aspect ratio button will automatically be hidden from the toolbar (default is true) bool
aspectRatioLockDimensionSwapEnabled If true, a custom aspect ratio is set, and the aspectRatioLockEnabled is set to true, the crop box will swap it's dimensions depending on portrait or landscape sized images. This value also controls whether the dimensions can swap when the image is rotated (default is false) bool
aspectRatioLockEnabled If true, while it can still be resized, the crop box will be locked to its current aspect ratio. If this is set to true, and resetAspectRatioEnabled is set to false, then the aspect ratio button will automatically be hidden from the toolbar (default is false) bool
title Title text that appears at the top of the view controller. String
doneButtonTitle Title for the 'Done' button. Setting this will override the Default which is a localized string for "Done" String
cancelButtonTitle Title for the 'Cancel' button. Setting this will override the Default which is a localized string for "Cancel" String

Example


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,
      )
    );
    

Credits

Copyright 2013, the Dart project authors. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Google Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

简介

A Flutter plugin for Android and iOS supports cropping images 展开 收起
BSD-3-Clause
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wzp520_748/flutter_image_cropper.git
git@gitee.com:wzp520_748/flutter_image_cropper.git
wzp520_748
flutter_image_cropper
flutter_image_cropper
master

搜索帮助