# SimpleCropView **Repository Path**: xhl_harmonyos/simple-crop-view ## Basic Information - **Project Name**: SimpleCropView - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-08-25 - **Last Updated**: 2025-09-16 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # @ohos/simple-crop-view ## 简介 @ohos/simple-crop-view是一个图像裁剪库,支持图片选择,多角度图片旋转,多种裁剪模式,提供了用于自定义的用户界面,以便于在需要处理和展示图片的应用中对图片进行裁剪。 ## 安装教程 ``` ohpm install @ohos/simple-crop-view ``` OpenHarmony ohpm环境配置等更多内容,请参考 [如何安装OpenHarmony ohpm包](https://gitcode.com/openharmony-tpc/docs/blob/master/OpenHarmony_har_usage.md) 。 ## 使用说明 ### 使用CropImageView组件 ``` @State sourceImg: PixelMap | undefined = undefined @State region: Region | undefined = undefined @State cropMode: CropMode = CropMode.FIT_IMAGE CropImageView({ sourceImg: this.sourceImg, region: this.region, cropMode: this.cropMode }) ``` ### 图片选择 ``` Image($r('app.media.ic_photo_library')) .width(24) .height(24) .onClick(async () => { const pixelMap = await pickImage() if (!pixelMap) { return } this.sourceImg = pixelMap }) ``` ### 图片旋转 ``` Image($r("app.media.ic_rotate_left")) .width(24) .height(24) .onClick(async () => { this.sourceImg = await rotateImage(this.sourceImg!, RotateDegrees.ROTATE_M90D) }) Image($r("app.media.ic_rotate_right")) .width(24) .height(24) .onClick(async () => { this.sourceImg = await rotateImage(this.sourceImg!, RotateDegrees.ROTATE_90D) }) ``` ### 图片裁剪并保存 ``` Image($r('app.media.ic_done')) .width(24) .height(24) .onClick(async () => { try { await cropImage(this.sourceImg!, this.region!, this.cropMode) promptAction.showToast({ message: '保存成功' }) } catch (e) { if (e.code = '13900012') { promptAction.showToast({ message: '请检查权限' }) return } promptAction.showToast({ message: JSON.stringify(e) }) } }) ``` ## 接口说明 ### 1.pickImage 选择图片 | 参数名 | 类型 | 必填 | 说明 | |-----|----|-----|--| | `无` | | | | --- ### 2.rotateImage 图片旋转 | 参数名 | 类型 | 必填 | 说明 | |----|--|----|------| | `pm` | `PixelMap` | 是 | 当前页面中显示的图像 | | `degrees` | `RotateDegrees` | 是 | 旋转角度 | --- ### 3.cropImage 图片裁剪并保存 | 参数名 | 类型 | 必填 | 说明 | |----|--|----|----------| | `src` | `PixelMap` | 是 | 当前页面中显示的图像 | | `region` | `Region` | 是 | 裁剪区域 | | `cropMode` | `CropMode` | 是 | 裁剪模式 | ## 关于混淆 - 代码混淆,请查看[代码混淆简介](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/source-obfuscation.md)。 - 如果希望库在代码混淆过程中不会被混淆,需要在混淆规则配置文件obfuscation-rules.txt中添加相应的排除规则: ``` -keep ./oh_modules/@ohos/simple-crop-view ``` ## 约束与限制 在下述版本验证通过: - DevEco Studio: 5.0 (5.0.3.500), SDK: API12 (5.0.0.25)。 ## 贡献代码 使用过程中发现任何问题都可以提 [Issue](https://gitcode.com/openharmony-tpc/ohos_mpchart/issues)给组件 ,当然,也非常欢迎发 [PR](https://gitcode.com/openharmony-tpc/ohos_mpchart/pulls)共建 。 ## 开源协议 本项目基于 [MIT License]() ,请自由地享受和参与开源。