1 Star 0 Fork 0

hihopeorg / we-cropper

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

we-cropper

简介

we-cropper是一款图片裁剪器,支持图片裁剪、设置裁剪区域等功能

下载安装

npm install @ohos/we-cropper --save

OpenHarmony npm环境配置等更多内容,请参考 如何安装OpenHarmony npm包

使用说明

hml文件引入

<element name='wecropper' src='wecropper/src/main/js/component/index/index.hml'></element>
<div class="container">
    <wecropper id='wecropper' cropper-opt="{{cropperOpt}}" ></wecropper>
    <div class="cropper-buttons">
        <text class="text" onclick="uploadTap">上传图片</text>
        <text class="text" onclick="removeImage">移除图片</text>
        <text class="text" onclick="getCropperImage">生成图片</text>
    </div>
</div>

js文件设置相关属性

   export default {
    data: {
        cropperOpt: {
            id: 'cropper',
            targetId: 'targetCropper',
            pixelRatio: 1,//设置屏幕密度
            width: 720,//设置显示区域宽度
            height: 720,//设置显示区域高度
            scale: 2.5,//设置缩放最大值
            zoom: 8,//设置缩放因子
			cut: {
                x: 10,//设置裁剪框左上角x坐标
                y: 200,//设置裁剪框左上角y坐标
                width: 700,//设置裁剪框宽度
                height: 700//设置裁剪框高度
            },
            boundStyle: {
                color: config.active,//设置裁剪框边角颜色
                mask: 'rgba(0,0,0,0.8)',//设置裁剪框遮罩层颜色
                lineWidth: 1//设置裁剪框边角线条粗细
            }
        },
        i:0,
    },
    onInit() {

    },
    uploadTap() {
        let temp = this.i%2 == 0?'common/images/bg-tv.jpg':'common/images/BaseAapter_test_1.PNG'
        this.$child('wecropper').pushOrign(temp)//加载图片
        this.i++
    },

    removeImage() {
        this.$child('wecropper').removeImage()//移除图片
    },

    getCropperImage() {
        this.$child('wecropper').getCropperImage()//裁剪图片
    }
}

接口说明

  1. 设置屏幕密度 pixelRatio: 1
  2. 设置显示区域宽度 width: 720
  3. 设置显示区域高度 height: 720
  4. 设置缩放最大值 scale: 2.5
  5. 设置缩放因子 zoom: 8
  6. 设置裁剪框左上角x坐标 cut:{x: 10}
  7. 设置裁剪框左上角y坐标 cut:{y: 200}
  8. 设置裁剪框宽度 cut:{width: 700}
  9. 设置裁剪框高度 cut:{height: 700}
  10. 设置裁剪框边角颜色 boundStyle:{color: config.active}
  11. 设置裁剪框遮罩层颜色 boundStyle:{mask: 'rgba(0,0,0,0.8)'}
  12. 设置裁剪框边角线条粗细 boundStyle:{lineWidth: 1}

兼容性

支持 OpenHarmony API version 8 及以上版本。

目录结构

|---- wecropper  
|     |---- entry  # 示例代码文件夹
|     |---- wecropper  # wecropper库文件夹
|           |---- src\main\js\components\index  # 源代码文件夹
|           		|---- index.css   # we-cropper组件样式控制源代码
|           		|---- index.hml 	# we-cropper组件界面源代码
|           		|---- index.js 		# we-cropper组件功能源代码
|           |---- index.ets  # 对外接口
|     |---- README.MD  # 安装使用方法                    

贡献代码

使用过程中发现任何问题都可以提 Issue 给我们,当然,我们也非常欢迎你给我们发 PR

开源协议

本项目基于 MIT License ,请自由地享受和参与开源。

MIT License Copyright (c) 2017 dlhandsome Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

canvas图片裁剪器 展开 收起
JavaScript 等 2 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/hihopeorg/we-cropper.git
git@gitee.com:hihopeorg/we-cropper.git
hihopeorg
we-cropper
we-cropper
master

搜索帮助