android 裁剪图片插件,支持裁剪图像适用于Android和iOS的Flutter插件

Image Cropper

68747470733a2f2f696d672e736869656c64732e696f2f7075622f762f696d6167655f63726f707065722e737667

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

68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f77617463686572732f59616c616e7469732f7543726f702e7376673f7374796c653d736f6369616c266c6162656c3d5761746368266d61784167653d3235393230303068747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f59616c616e7469732f7543726f702e7376673f7374796c653d736f6369616c266c6162656c3d53746172266d61784167653d3235393230303068747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f59616c616e7469732f7543726f702e7376673f7374796c653d736f6369616c266c6162656c3d466f726b266d61784167653d3235393230303068747470733a2f2f6a69747061636b2e696f2f762f59616c616e7469732f7543726f702e73766768747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d417061636865253230322e302d626c75652e737667

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

ff6be358d54c548a2d1ef61b0d267b01.gif

TOCropViewController - TimOliver

68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f77617463686572732f54696d4f6c697665722f544f43726f7056696577436f6e74726f6c6c65722e7376673f7374796c653d736f6369616c266c6162656c3d5761746368266d61784167653d3235393230303068747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f54696d4f6c697665722f544f43726f7056696577436f6e74726f6c6c65722e7376673f7374796c653d736f6369616c266c6162656c3d53746172266d61784167653d3235393230303068747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f54696d4f6c697665722f544f43726f7056696577436f6e74726f6c6c65722e7376673f7374796c653d736f6369616c266c6162656c3d466f726b266d61784167653d3235393230303068747470733a2f2f696d672e736869656c64732e696f2f636f636f61706f64732f762f544f43726f7056696577436f6e74726f6c6c65722e7376673f7374796c653d666c617468747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667

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.

989308eeb74c518cc4309184ff08edb8.gif

How to install

Android

Add UCropActivity into your AndroidManifest.xml

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 我不是很清楚Flutter打包androidios的具体流程,但是根据我从网上查询的信息,可以通过使用Flutter CLI来打包AndroidiOS应用程序,并使用Flutter提供的构建工具来生成最终的应用程序文件。 ### 回答2: Flutter是一种开源的跨平台移动应用开发框架,它可以同时打包AndroidiOS两个平台的应用。下面将分别介绍Flutter打包AndroidiOS的步骤。 Flutter打包Android应用的步骤如下: 1. 首先,我们需要在Flutter项目的根目录下执行命令`flutter build apk`,该命令会利用Flutter的打包工具将代码编译成Android应用可执行文件。 2. 打包完成后,在项目的`build/app/outputs/apk/release`路径下会生成一个名为`app.apk`的文件,这就是我们需要的Android安装包。 3. 如果需要对该安装包进行签名,可以使用Java开发工具包(JDK)自带的`keytool`生成一个密钥库文件(keystore),然后利用Android Studio自带的`apksigner`工具对APK进行签名。 4. 最后,我们可以将签名后的APK安装包通过各种方式进行发布和安装。 Flutter打包iOS应用的步骤如下: 1. 在Flutter项目的根目录下执行命令`flutter build ios`,该命令会利用Flutter的打包工具将代码编译成iOS应用可执行文件。 2. 打包完成后,在项目的`build/ios/iphoneos`路径下会生成一个名为`Runner.app`的文件,这就是我们需要的iOS应用。 3. 接下来,我们需要在Xcode中打开`Runner.xcworkspace`文件,并配置开发者账号和相关证书。 4. 在Xcode中选择设备或模拟器,然后点击菜单栏的`Product -> Archive`选项,Xcode将会对应用进行打包。 5. 打包完成后,在`Xcode -> Window -> Organizer`界面中可以找到App Archives,我们可以选择对应的应用版本进行导出或发布。 总结来说,Flutter通过使用自身的打包工具,可以快速便捷地打包AndroidiOS应用,对于开发者来说非常方便。同时,开发者还可以根据需要对打包后的应用进行签名或发布。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值