更新记录
1.0.2(2026-03-15)
删除不需要的文件
1.0.1(2026-03-15)
更换架构
1.0.0(2026-03-14)
初始化安卓版
查看更多平台兼容性
uni-app(5.03)
| Vue2 | Vue2插件版本 | Vue3 | Vue3插件版本 | Chrome | Safari | app-vue | app-nvue | app-nvue插件版本 | Android | iOS | 鸿蒙 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| √ | 1.0.0 | √ | 1.0.0 | - | - | × | √ | 1.0.0 | 8.0 | × | - |
| 微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 小红书小程序 | 快应用-华为 | 快应用-联盟 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| - | - | - | - | - | - | - | - | - | - | - | - |
rd-ImageCropper
图片裁剪插件,基于 UCrop 实现。
功能特性
- UI 交互式裁剪界面
- 支持旋转、缩放、自由裁剪
- 自定义输出质量和尺寸
- 支持本地路径、file://、content:// 格式的图片
- 丰富的 UI 自定义选项
安装
将 uni_modules/rd-ImageCropper 目录复制到项目的 uni_modules 目录下。
使用方法
import { cropImage } from '@/uni_modules/rd-ImageCropper'
// 基础用法
cropImage(
'/path/to/image.jpg',
{ quality: 90 },
(path) => console.log('裁剪成功:', path),
() => console.log('取消裁剪'),
(msg) => console.log('裁剪错误:', msg)
)
// 完整配置
cropImage(
imagePath,
{
quality: 90,
aspectRatioX: 1,
aspectRatioY: 1,
maxResultWidth: 2000,
maxResultHeight: 2000,
toolbarColor: '#000000',
activeControlsWidgetColor: '#07C160',
toolbarTitle: '裁剪头像'
},
onSuccess,
onCancel,
onError
)
API
cropImage(imagePath, options?, onSuccess?, onCancel?, onError?)
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| imagePath | string | 是 | 图片路径(本地路径、file:// 或 content://) |
| options | object | 否 | 裁剪选项 |
| onSuccess | function | 否 | 成功回调,参数为裁剪后的图片路径 |
| onCancel | function | 否 | 取消回调 |
| onError | function | 否 | 错误回调,参数为错误信息 |
options 配置
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| quality | number | 90 | 压缩质量 (0-100) |
| aspectRatioX | number | 1 | 裁剪宽高比 X |
| aspectRatioY | number | 1 | 裁剪宽高比 Y |
| maxResultWidth | number | 2000 | 最大输出宽度 |
| maxResultHeight | number | 2000 | 最大输出高度 |
| maxScaleMultiplier | number | 10 | 最大缩放倍数 |
| maxBitmapSize | number | 0 | 最大位图大小 (0=不限制) |
| imageToCropBoundsAnimDuration | number | 500 | 动画时长(ms) |
| dimmedLayerColor | string | "rgba(0,0,0,0.6)" | 遮罩层颜色 |
| circleDimmedLayer | boolean | false | 圆形遮罩 |
| showCropFrame | boolean | true | 显示裁剪框 |
| cropFrameColor | string | "#FFFFFF" | 裁剪框颜色 |
| cropFrameStrokeWidth | number | 3 | 裁剪框线宽 |
| showCropGrid | boolean | true | 显示裁剪网格 |
| cropGridRowCount | number | 2 | 网格行数 |
| cropGridColumnCount | number | 2 | 网格列数 |
| cropGridColor | string | "#FFFFFF" | 网格颜色 |
| cropGridStrokeWidth | number | 1 | 网格线宽 |
| hideBottomControls | boolean | false | 隐藏底部控制栏 |
| freeStyleCropEnabled | boolean | true | 启用自由裁剪 |
| activeControlsWidgetColor | string | "#07C160" | 控件激活颜色 |
| toolbarColor | string | "#000000" | 工具栏背景色 |
| toolbarWidgetColor | string | "#FFFFFF" | 工具栏控件颜色 |
| rootViewBackgroundColor | string | "#000000" | 根视图背景色 |
| statusBarLight | boolean | false | 状态栏亮色模式 |
| navigationBarLight | boolean | false | 导航栏亮色模式 |
| toolbarTitle | string | "图片裁剪" | 工具栏标题 |
颜色格式支持
颜色参数支持以下格式:
// rgba 格式
dimmedLayerColor: "rgba(0, 0, 0, 0.6)"
// rgb 格式
toolbarColor: "rgb(33, 33, 33)"
// hex 格式
activeControlsWidgetColor: "#07C160"
cropFrameColor: "#FFFFFF"
// 颜色名称
cropGridColor: "white"
返回值
- 裁剪成功后返回裁剪后图片的绝对路径
- 图片保存在应用缓存目录
示例
头像裁剪 (1:1)
cropImage(
imagePath,
{
aspectRatioX: 1,
aspectRatioY: 1,
circleDimmedLayer: true,
toolbarTitle: '裁剪头像'
},
onSuccess,
onCancel,
onError
)
身份证裁剪 (4:3)
cropImage(
imagePath,
{
aspectRatioX: 4,
aspectRatioY: 3,
freeStyleCropEnabled: false,
toolbarTitle: '裁剪身份证'
},
onSuccess,
onCancel,
onError
)
平台支持
- Android
许可证
MIT

收藏人数:
购买普通授权版(
试用
赞赏(0)
下载 43
赞赏 0
下载 11756437
赞赏 1911
赞赏
京公网安备:11010802035340号