uniapp图片涂鸦插件(支持多种涂鸦方式,图片放大缩小)

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

工程下载地址https://download.csdn.net/download/qq_54123885/89290753

ct-graffiti涂鸦组件使用说明

参考说明

优化:

  • 增加图片放大缩小移动功能
  • 添加更多涂鸦图形的选择
  • 增加文字涂鸦功能 需要自己配置一个可用弹框输入文字后赋值给text(index文件384行)

组件引用方式

easycom方式引用

将yl-graffiti组件放入根目录下的components中:

|--components
|    |--yl-graffiti
|        |-yl-graffiti.vue
|--pages
|--pages.json

然后在pages.json文件中添加easycom声明:

{
    "easycom": {
        "autoscan": true,
        "custom": {
            "^yl-(.*)": "@/components/yl-$1/yl-$1.vue"
        }
    },
    ...
}

代码引用

同上,将yl-graffiti组件放入根目录下的components中或放在使用该组件页面对应的目录下,然后在页面中导入该组件:

<script>
    import ylGraffiti from "./components/yl-graffiti/yl-graffiti.vue";
    export default {
        components: {
            ylGraffiti
        },
        ...
    }
</script>

示例代码

组件使用相关代码,详细代码请参考示例工程,下面贴出主要代码。

<view>
    ...
    <yl-graffiti ref="graffiti" canvas-id="myCanvas" :width="canvasStyle.w" :height="canvasStyle.h"
		:shape="curShape" :lineColor="lineColor" :lineWidth="lineSize" :bgImage="picture"
		@stepChanged="stepChanged" :text="text" :optIndex="optIndex">
	</yl-graffiti>
    <!-- 涂鸦组件控制视图,省略 -->
    ...
</view>
<script>
    // 涂鸦组件功能由页面来控制
    import ylGraffiti from "./components/yl-graffiti/yl-graffiti.vue";
    
    export default {
        components: {
            ylGraffiti
        },
        data() {
            return {
            	text: '',//文字
            	optIndex: 3,
                stepInfo: { // 用来控制撤销和重做
                    curStep: -1,
                    len: 0
                },
                saving: false
            }
        },
        ...,
        methods: {
            ...,
            
            /**
             * 当前位置变化
             * @param {Object} e
             */
            stepChanged(e) {
                this.stepInfo = e;
            },
            
            /**
             * 选择涂鸦的类型
             * @param {Object} index
             */
            selectWritingOption(index) {
				switch (index) {
					case 0:
					case 1:
					case 2:
						this.optIndex = index;
						break;
					case 3:
						this.optIndex = index;
						break;
					case 4:
						this.$refs.graffiti.repeal();
						break;
					case 5:
						this.$refs.graffiti.redo();
						break;
					case 6:
						this.$refs.graffiti.clearBoard();
						break;
					default:
						break;
				}
			},    
            /**
             * 保存涂鸦
             */
            savePicture() {
                this.saving = true;
                this.$refs.graffiti.saveCanvas().then(res => {
                    this.pictures[this.swiperCurrent].url = res;
                    setTimeout(_ => this.saving = this.writing = false, 100);
                });
            }
        }
    }
</script>

组件接口

属性

参数说明类型默认值
canvasId画布IDstringMyCanvas
width画布宽度number300
height画布高度number225
shape画笔绘制图形形状stringcurve
lineColor画笔颜色string#091A22
lineWidth画笔宽度number5
bgColor背景颜色string
bgImage背景图片string
text文字涂鸦string文字文字
optIndex当前选择功能string、number3
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

前端程序猿i

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值